2016-11-30 05:51:36 +03:00
|
|
|
// Copyright 2016 The Grin Developers
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
extern crate grin_grin as grin;
|
|
|
|
extern crate grin_core as core;
|
|
|
|
extern crate grin_p2p as p2p;
|
|
|
|
extern crate grin_chain as chain;
|
2016-12-15 03:10:39 +03:00
|
|
|
|
2016-11-30 05:51:36 +03:00
|
|
|
extern crate env_logger;
|
2016-12-15 03:10:39 +03:00
|
|
|
extern crate futures;
|
|
|
|
extern crate tokio_core;
|
2016-11-30 05:51:36 +03:00
|
|
|
|
|
|
|
use std::io;
|
2016-12-14 06:21:49 +03:00
|
|
|
use std::thread;
|
2016-11-30 05:51:36 +03:00
|
|
|
use std::time;
|
|
|
|
|
2016-12-15 03:10:39 +03:00
|
|
|
use futures::Future;
|
|
|
|
use tokio_core::reactor;
|
|
|
|
|
2016-11-30 05:51:36 +03:00
|
|
|
#[test]
|
|
|
|
fn simulate_servers() {
|
|
|
|
env_logger::init().unwrap();
|
|
|
|
|
2016-12-15 03:10:39 +03:00
|
|
|
let mut evtlp = reactor::Core::new().unwrap();
|
|
|
|
let handle = evtlp.handle();
|
|
|
|
|
2016-12-14 06:21:49 +03:00
|
|
|
// instantiates 5 servers on different ports
|
|
|
|
let mut servers = vec![];
|
|
|
|
for n in 0..5 {
|
2016-12-15 03:10:39 +03:00
|
|
|
let s = grin::ServerFut::start(
|
2016-11-30 05:51:36 +03:00
|
|
|
grin::ServerConfig{
|
|
|
|
db_root: format!("target/grin-{}", n),
|
|
|
|
cuckoo_size: 18,
|
|
|
|
p2p_config: p2p::P2PConfig{port: 10000+n, ..p2p::P2PConfig::default()}
|
2016-12-15 03:10:39 +03:00
|
|
|
}, &handle).unwrap();
|
2016-11-30 05:51:36 +03:00
|
|
|
servers.push(s);
|
2016-12-14 06:21:49 +03:00
|
|
|
}
|
2016-11-30 05:51:36 +03:00
|
|
|
|
2016-12-14 06:21:49 +03:00
|
|
|
// everyone connects to everyone else
|
|
|
|
for n in 0..5 {
|
|
|
|
for m in 0..5 {
|
|
|
|
if m == n { continue }
|
|
|
|
let addr = format!("{}:{}", "127.0.0.1", 10000+m);
|
|
|
|
servers[n].connect_peer(addr.parse().unwrap()).unwrap();
|
|
|
|
println!("c {}", m);
|
2016-11-30 05:51:36 +03:00
|
|
|
}
|
2016-12-14 06:21:49 +03:00
|
|
|
}
|
2016-11-30 05:51:36 +03:00
|
|
|
|
2016-12-15 03:10:39 +03:00
|
|
|
let timeout = reactor::Timeout::new(time::Duration::new(1, 0), &handle.clone()).unwrap();
|
|
|
|
evtlp.run(timeout);
|
2016-11-30 05:51:36 +03:00
|
|
|
}
|