Files
@ e4a68057bfbe
Branch filter:
Location: CSY/reowolf/src/runtime/tests.rs - annotation
e4a68057bfbe
16.1 KiB
application/rls-services+xml
waker impl for setup phase connect. TODO test on Linux
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | 44a98be4e4b4 1bacc6467d19 d1a70dfdafba 65390fb1cdbc 41bf21c39c5b d1a70dfdafba d1a70dfdafba d1a70dfdafba 41bf21c39c5b 41bf21c39c5b 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 1bacc6467d19 44a98be4e4b4 44a98be4e4b4 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 44a98be4e4b4 44a98be4e4b4 41bf21c39c5b b20c3a55156d 44a98be4e4b4 44a98be4e4b4 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 44a98be4e4b4 8642f7a7bf01 41bf21c39c5b 41bf21c39c5b 8642f7a7bf01 8642f7a7bf01 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 8642f7a7bf01 41bf21c39c5b 41bf21c39c5b 8642f7a7bf01 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 8642f7a7bf01 41bf21c39c5b 41bf21c39c5b 44a98be4e4b4 41bf21c39c5b 41bf21c39c5b 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 41bf21c39c5b 41bf21c39c5b d1a70dfdafba 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 44a98be4e4b4 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b d1a70dfdafba 44a98be4e4b4 1bacc6467d19 1bacc6467d19 b20c3a55156d 1bacc6467d19 b20c3a55156d 1bacc6467d19 1bacc6467d19 41bf21c39c5b 41bf21c39c5b d1a70dfdafba 1bacc6467d19 1bacc6467d19 41bf21c39c5b 41bf21c39c5b d1a70dfdafba 1bacc6467d19 1bacc6467d19 1bacc6467d19 1bacc6467d19 1e7064d79bdb 1e7064d79bdb 1e7064d79bdb 41bf21c39c5b 41bf21c39c5b 1e7064d79bdb d1a70dfdafba 1e7064d79bdb 1e7064d79bdb 1e7064d79bdb 1e7064d79bdb 1e7064d79bdb 41bf21c39c5b 41bf21c39c5b 1e7064d79bdb d1a70dfdafba 1e7064d79bdb 1e7064d79bdb 1e7064d79bdb 1e7064d79bdb 1e7064d79bdb 41bf21c39c5b 41bf21c39c5b 1e7064d79bdb d1a70dfdafba 1e7064d79bdb 1e7064d79bdb 1e7064d79bdb 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 41bf21c39c5b 41bf21c39c5b d1a70dfdafba d1a70dfdafba 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 41bf21c39c5b 41bf21c39c5b 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 41bf21c39c5b 41bf21c39c5b 3f6d45f84e76 d1a70dfdafba 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 3f6d45f84e76 41bf21c39c5b 41bf21c39c5b 3f6d45f84e76 d1a70dfdafba d1a70dfdafba 3f6d45f84e76 3f6d45f84e76 842acacee86d 842acacee86d 842acacee86d 41bf21c39c5b 41bf21c39c5b 842acacee86d d1a70dfdafba 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d 41bf21c39c5b 41bf21c39c5b 842acacee86d d1a70dfdafba 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d 41bf21c39c5b 41bf21c39c5b 842acacee86d d1a70dfdafba 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d 842acacee86d a3ca8e491622 41bf21c39c5b 41bf21c39c5b 842acacee86d d1a70dfdafba 842acacee86d 842acacee86d d1a70dfdafba 842acacee86d 842acacee86d 842acacee86d a3ca8e491622 41bf21c39c5b 842acacee86d 842acacee86d 842acacee86d 41bf21c39c5b 41bf21c39c5b d1a70dfdafba 842acacee86d d1a70dfdafba a34c55297ac2 842acacee86d 842acacee86d 41bf21c39c5b 41bf21c39c5b d1a70dfdafba 842acacee86d d1a70dfdafba 842acacee86d 842acacee86d 842acacee86d 842acacee86d a3ca8e491622 a3ca8e491622 a3ca8e491622 41bf21c39c5b 41bf21c39c5b a3ca8e491622 d1a70dfdafba a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 d1a70dfdafba a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 41bf21c39c5b a3ca8e491622 a3ca8e491622 a3ca8e491622 41bf21c39c5b 41bf21c39c5b d1a70dfdafba a3ca8e491622 a3ca8e491622 d1a70dfdafba a3ca8e491622 a3ca8e491622 a3ca8e491622 41bf21c39c5b 41bf21c39c5b d1a70dfdafba a3ca8e491622 d1a70dfdafba a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 b20c3a55156d b20c3a55156d b20c3a55156d b20c3a55156d 41bf21c39c5b e7b7d53e6952 e7b7d53e6952 d1a70dfdafba a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 a3ca8e491622 b20c3a55156d b20c3a55156d b20c3a55156d b20c3a55156d b20c3a55156d 41bf21c39c5b e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 d1a70dfdafba a3ca8e491622 a3ca8e491622 d1a70dfdafba a3ca8e491622 a3ca8e491622 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 41bf21c39c5b e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 41bf21c39c5b e7b7d53e6952 41bf21c39c5b 41bf21c39c5b e7b7d53e6952 d1a70dfdafba e7b7d53e6952 e7b7d53e6952 41bf21c39c5b e7b7d53e6952 41bf21c39c5b 41bf21c39c5b e7b7d53e6952 d1a70dfdafba e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 b20c3a55156d e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 41bf21c39c5b e7b7d53e6952 41bf21c39c5b 41bf21c39c5b e7b7d53e6952 e7b7d53e6952 d1a70dfdafba d1a70dfdafba e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 41bf21c39c5b e7b7d53e6952 41bf21c39c5b 41bf21c39c5b e7b7d53e6952 d1a70dfdafba e7b7d53e6952 e7b7d53e6952 d1a70dfdafba e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 e7b7d53e6952 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 41bf21c39c5b 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 41bf21c39c5b 41bf21c39c5b 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc 65390fb1cdbc | use crate as reowolf;
use crossbeam_utils::thread::scope;
use reowolf::{
error::*,
EndpointPolarity::{Active, Passive},
Polarity::{Getter, Putter},
*,
};
use std::{fs::File, net::SocketAddr, path::Path, sync::Arc, time::Duration};
//////////////////////////////////////////
fn next_test_addr() -> SocketAddr {
use std::{
net::{Ipv4Addr, SocketAddrV4},
sync::atomic::{AtomicU16, Ordering::SeqCst},
};
static TEST_PORT: AtomicU16 = AtomicU16::new(5_000);
let port = TEST_PORT.fetch_add(1, SeqCst);
SocketAddrV4::new(Ipv4Addr::LOCALHOST, port).into()
}
lazy_static::lazy_static! {
static ref MINIMAL_PROTO: Arc<ProtocolDescription> =
{ Arc::new(reowolf::ProtocolDescription::parse(b"").unwrap()) };
}
fn file_logged_connector(connector_id: ConnectorId, dir_path: &Path) -> Connector {
let _ = std::fs::create_dir(dir_path); // we will check failure soon
let path = dir_path.join(format!("cid_{:?}.txt", connector_id));
let file = File::create(path).unwrap();
let file_logger = Box::new(FileLogger::new(connector_id, file));
Connector::new(file_logger, MINIMAL_PROTO.clone(), connector_id, 8)
}
//////////////////////////////////////////
#[test]
fn basic_connector() {
Connector::new(Box::new(DummyLogger), MINIMAL_PROTO.clone(), 0, 0);
}
#[test]
fn basic_logged_connector() {
let test_log_path = Path::new("./logs/basic_logged_connector");
file_logged_connector(0, test_log_path);
}
#[test]
fn new_port_pair() {
let test_log_path = Path::new("./logs/new_port_pair");
let mut c = file_logged_connector(0, test_log_path);
let [_, _] = c.new_port_pair();
let [_, _] = c.new_port_pair();
}
#[test]
fn new_sync() {
let test_log_path = Path::new("./logs/new_sync");
let mut c = file_logged_connector(0, test_log_path);
let [o, i] = c.new_port_pair();
c.add_component(b"sync", &[i, o]).unwrap();
}
#[test]
fn new_net_port() {
let test_log_path = Path::new("./logs/new_net_port");
let mut c = file_logged_connector(0, test_log_path);
let sock_addr = next_test_addr();
let _ = c.new_net_port(Getter, sock_addr, Passive).unwrap();
let _ = c.new_net_port(Putter, sock_addr, Active).unwrap();
}
#[test]
fn trivial_connect() {
let test_log_path = Path::new("./logs/trivial_connect");
let mut c = file_logged_connector(0, test_log_path);
c.connect(Some(Duration::from_secs(1))).unwrap();
}
#[test]
fn single_node_connect() {
let sock_addr = next_test_addr();
let test_log_path = Path::new("./logs/single_node_connect");
let mut c = file_logged_connector(0, test_log_path);
let _ = c.new_net_port(Getter, sock_addr, Passive).unwrap();
let _ = c.new_net_port(Putter, sock_addr, Active).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
}
#[test]
fn minimal_net_connect() {
let sock_addr = next_test_addr();
let test_log_path = Path::new("./logs/minimal_net_connect");
scope(|s| {
s.spawn(|_| {
let mut c = file_logged_connector(0, test_log_path);
let _ = c.new_net_port(Getter, sock_addr, Active).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
});
s.spawn(|_| {
let mut c = file_logged_connector(1, test_log_path);
let _ = c.new_net_port(Putter, sock_addr, Passive).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
});
})
.unwrap();
}
#[test]
fn put_no_sync() {
let test_log_path = Path::new("./logs/put_no_sync");
let mut c = file_logged_connector(0, test_log_path);
let [o, _] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.put(o, (b"hi" as &[_]).into()).unwrap();
}
#[test]
fn wrong_polarity_bad() {
let test_log_path = Path::new("./logs/wrong_polarity_bad");
let mut c = file_logged_connector(0, test_log_path);
let [_, i] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.put(i, (b"hi" as &[_]).into()).unwrap_err();
}
#[test]
fn dup_put_bad() {
let test_log_path = Path::new("./logs/dup_put_bad");
let mut c = file_logged_connector(0, test_log_path);
let [o, _] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.put(o, (b"hi" as &[_]).into()).unwrap();
c.put(o, (b"hi" as &[_]).into()).unwrap_err();
}
#[test]
fn trivial_sync() {
let test_log_path = Path::new("./logs/trivial_sync");
let mut c = file_logged_connector(0, test_log_path);
c.connect(Some(Duration::from_secs(1))).unwrap();
c.sync(Some(Duration::from_secs(1))).unwrap();
}
#[test]
fn unconnected_gotten_err() {
let test_log_path = Path::new("./logs/unconnected_gotten_err");
let mut c = file_logged_connector(0, test_log_path);
let [_, i] = c.new_port_pair();
assert_eq!(reowolf::error::GottenError::NoPreviousRound, c.gotten(i).unwrap_err());
}
#[test]
fn connected_gotten_err_no_round() {
let test_log_path = Path::new("./logs/connected_gotten_err_no_round");
let mut c = file_logged_connector(0, test_log_path);
let [_, i] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
assert_eq!(reowolf::error::GottenError::NoPreviousRound, c.gotten(i).unwrap_err());
}
#[test]
fn connected_gotten_err_ungotten() {
let test_log_path = Path::new("./logs/connected_gotten_err_ungotten");
let mut c = file_logged_connector(0, test_log_path);
let [_, i] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.sync(Some(Duration::from_secs(1))).unwrap();
assert_eq!(reowolf::error::GottenError::PortDidntGet, c.gotten(i).unwrap_err());
}
#[test]
fn native_polarity_checks() {
let test_log_path = Path::new("./logs/native_polarity_checks");
let mut c = file_logged_connector(0, test_log_path);
let [o, i] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
// fail...
c.get(o).unwrap_err();
c.put(i, (b"hi" as &[_]).into()).unwrap_err();
// succeed..
c.get(i).unwrap();
c.put(o, (b"hi" as &[_]).into()).unwrap();
}
#[test]
fn native_multiple_gets() {
let test_log_path = Path::new("./logs/native_multiple_gets");
let mut c = file_logged_connector(0, test_log_path);
let [_, i] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.get(i).unwrap();
c.get(i).unwrap_err();
}
#[test]
fn next_batch() {
let test_log_path = Path::new("./logs/next_batch");
let mut c = file_logged_connector(0, test_log_path);
c.next_batch().unwrap_err();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.next_batch().unwrap();
c.next_batch().unwrap();
c.next_batch().unwrap();
}
#[test]
fn native_self_msg() {
let test_log_path = Path::new("./logs/native_self_msg");
let mut c = file_logged_connector(0, test_log_path);
let [o, i] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.get(i).unwrap();
c.put(o, (b"hi" as &[_]).into()).unwrap();
c.sync(Some(Duration::from_secs(1))).unwrap();
}
#[test]
fn two_natives_msg() {
let test_log_path = Path::new("./logs/two_natives_msg");
let sock_addr = next_test_addr();
scope(|s| {
s.spawn(|_| {
let mut c = file_logged_connector(0, test_log_path);
let g = c.new_net_port(Getter, sock_addr, Active).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.get(g).unwrap();
c.sync(Some(Duration::from_secs(1))).unwrap();
c.gotten(g).unwrap();
});
s.spawn(|_| {
let mut c = file_logged_connector(1, test_log_path);
let p = c.new_net_port(Putter, sock_addr, Passive).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.put(p, (b"hello" as &[_]).into()).unwrap();
c.sync(Some(Duration::from_secs(1))).unwrap();
});
})
.unwrap();
}
#[test]
fn trivial_nondet() {
let test_log_path = Path::new("./logs/trivial_nondet");
let mut c = file_logged_connector(0, test_log_path);
let [_, i] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.get(i).unwrap();
// getting 0 batch
c.next_batch().unwrap();
// silent 1 batch
assert_eq!(1, c.sync(Some(Duration::from_secs(1))).unwrap());
c.gotten(i).unwrap_err();
}
#[test]
fn connector_pair_nondet() {
let test_log_path = Path::new("./logs/connector_pair_nondet");
let sock_addr = next_test_addr();
scope(|s| {
s.spawn(|_| {
let mut c = file_logged_connector(0, test_log_path);
let g = c.new_net_port(Getter, sock_addr, Active).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.next_batch().unwrap();
c.get(g).unwrap();
assert_eq!(1, c.sync(Some(Duration::from_secs(1))).unwrap());
c.gotten(g).unwrap();
});
s.spawn(|_| {
let mut c = file_logged_connector(1, test_log_path);
let p = c.new_net_port(Putter, sock_addr, Passive).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.put(p, (b"hello" as &[_]).into()).unwrap();
c.sync(Some(Duration::from_secs(1))).unwrap();
});
})
.unwrap();
}
#[test]
fn cannot_use_moved_ports() {
/*
native p|-->|g sync
*/
let test_log_path = Path::new("./logs/cannot_use_moved_ports");
let mut c = file_logged_connector(0, test_log_path);
let [p, g] = c.new_port_pair();
c.add_component(b"sync", &[g, p]).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.put(p, (b"hello" as &[_]).into()).unwrap_err();
c.get(g).unwrap_err();
}
#[test]
fn sync_sync() {
/*
native p0|-->|g0 sync
g1|<--|p1
*/
let test_log_path = Path::new("./logs/sync_sync");
let mut c = file_logged_connector(0, test_log_path);
let [p0, g0] = c.new_port_pair();
let [p1, g1] = c.new_port_pair();
c.add_component(b"sync", &[g0, p1]).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.put(p0, (b"hello" as &[_]).into()).unwrap();
c.get(g1).unwrap();
c.sync(Some(Duration::from_secs(1))).unwrap();
c.gotten(g1).unwrap();
}
#[test]
fn double_net_connect() {
let test_log_path = Path::new("./logs/double_net_connect");
let sock_addrs = [next_test_addr(), next_test_addr()];
scope(|s| {
s.spawn(|_| {
let mut c = file_logged_connector(0, test_log_path);
let [_p, _g] = [
c.new_net_port(Putter, sock_addrs[0], Active).unwrap(),
c.new_net_port(Getter, sock_addrs[1], Active).unwrap(),
];
c.connect(Some(Duration::from_secs(1))).unwrap();
});
s.spawn(|_| {
let mut c = file_logged_connector(1, test_log_path);
let [_g, _p] = [
c.new_net_port(Getter, sock_addrs[0], Passive).unwrap(),
c.new_net_port(Putter, sock_addrs[1], Passive).unwrap(),
];
c.connect(Some(Duration::from_secs(1))).unwrap();
});
})
.unwrap();
}
#[test]
fn distributed_msg_bounce() {
/*
native[0] | sync 0.p|-->|1.p native[1]
0.g|<--|1.g
*/
let test_log_path = Path::new("./logs/distributed_msg_bounce");
let sock_addrs = [next_test_addr(), next_test_addr()];
scope(|s| {
s.spawn(|_| {
/*
native | sync p|-->
| g|<--
*/
let mut c = file_logged_connector(0, test_log_path);
let [p, g] = [
c.new_net_port(Putter, sock_addrs[0], Active).unwrap(),
c.new_net_port(Getter, sock_addrs[1], Active).unwrap(),
];
c.add_component(b"sync", &[g, p]).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.sync(Some(Duration::from_secs(1))).unwrap();
});
s.spawn(|_| {
/*
native p|-->
g|<--
*/
let mut c = file_logged_connector(1, test_log_path);
let [g, p] = [
c.new_net_port(Getter, sock_addrs[0], Passive).unwrap(),
c.new_net_port(Putter, sock_addrs[1], Passive).unwrap(),
];
c.connect(Some(Duration::from_secs(1))).unwrap();
c.put(p, (b"hello" as &[_]).into()).unwrap();
c.get(g).unwrap();
c.sync(Some(Duration::from_secs(1))).unwrap();
c.gotten(g).unwrap();
});
})
.unwrap();
}
#[test]
fn local_timeout() {
let test_log_path = Path::new("./logs/local_timeout");
let mut c = file_logged_connector(0, test_log_path);
let [_, g] = c.new_port_pair();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.get(g).unwrap();
match c.sync(Some(Duration::from_millis(200))) {
Err(SyncError::RoundFailure) => {}
res => panic!("expeted timeout. but got {:?}", res),
}
}
#[test]
fn parent_timeout() {
let test_log_path = Path::new("./logs/parent_timeout");
let sock_addr = next_test_addr();
scope(|s| {
s.spawn(|_| {
// parent; times out
let mut c = file_logged_connector(999, test_log_path);
let _ = c.new_net_port(Putter, sock_addr, Active).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.sync(Some(Duration::from_millis(300))).unwrap_err(); // timeout
});
s.spawn(|_| {
// child
let mut c = file_logged_connector(000, test_log_path);
let g = c.new_net_port(Getter, sock_addr, Passive).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.get(g).unwrap(); // not matched by put
c.sync(None).unwrap_err(); // no timeout
});
})
.unwrap();
}
#[test]
fn child_timeout() {
let test_log_path = Path::new("./logs/child_timeout");
let sock_addr = next_test_addr();
scope(|s| {
s.spawn(|_| {
// child; times out
let mut c = file_logged_connector(000, test_log_path);
let _ = c.new_net_port(Putter, sock_addr, Active).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.sync(Some(Duration::from_millis(300))).unwrap_err(); // timeout
});
s.spawn(|_| {
// parent
let mut c = file_logged_connector(999, test_log_path);
let g = c.new_net_port(Getter, sock_addr, Passive).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
c.get(g).unwrap(); // not matched by put
c.sync(None).unwrap_err(); // no timeout
});
})
.unwrap();
}
#[test]
fn chain_connect() {
let test_log_path = Path::new("./logs/chain_connect");
let sock_addrs = [next_test_addr(), next_test_addr(), next_test_addr(), next_test_addr()];
scope(|s| {
s.spawn(|_| {
let mut c = file_logged_connector(0, test_log_path);
c.new_net_port(Putter, sock_addrs[0], Passive).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
});
s.spawn(|_| {
let mut c = file_logged_connector(10, test_log_path);
c.new_net_port(Getter, sock_addrs[0], Active).unwrap();
c.new_net_port(Putter, sock_addrs[1], Passive).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
});
s.spawn(|_| {
// LEADER
let mut c = file_logged_connector(7, test_log_path);
c.new_net_port(Getter, sock_addrs[1], Active).unwrap();
c.new_net_port(Putter, sock_addrs[2], Passive).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
});
s.spawn(|_| {
let mut c = file_logged_connector(4, test_log_path);
c.new_net_port(Getter, sock_addrs[2], Active).unwrap();
c.new_net_port(Putter, sock_addrs[3], Passive).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
});
s.spawn(|_| {
let mut c = file_logged_connector(1, test_log_path);
c.new_net_port(Getter, sock_addrs[3], Active).unwrap();
c.connect(Some(Duration::from_secs(1))).unwrap();
});
})
.unwrap();
}
|