Skip to content

Commit 071296b

Browse files
committed
integration_tests: add simple test for multibackend
1 parent bac3320 commit 071296b

File tree

7 files changed

+36
-10
lines changed

7 files changed

+36
-10
lines changed

tests/basic.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,9 @@ impl IntegrationTest for TestBasicSerialize {
7676
fn basic() {
7777
let log = libccp_integration::logger();
7878
info!(log, "starting basic test");
79-
libccp_integration::run_test::<TestBasicSerialize>(log, 1);
79+
libccp_integration::run_test::<TestBasicSerialize>(log, 1, false);
80+
81+
let log2 = libccp_integration::logger();
82+
info!(log2, "starting basic test (multi)");
83+
libccp_integration::run_test::<TestBasicSerialize>(log2, 1, true);
8084
}

tests/libccp_integration/mod.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<I: Ipc, T: IntegrationTest> Flow for TestBase<I, T> {
8080
}
8181

8282
use portus::ipc::chan::Socket;
83-
use portus::ipc::{SingleBackendBuilder, Blocking};
83+
use portus::ipc::{Blocking, MultiBackendBuilder, SingleBackendBuilder};
8484
use std;
8585
use std::thread;
8686

@@ -100,8 +100,27 @@ fn start_ccp<T: IntegrationTest + 'static + Send>(
100100
)
101101
}
102102

103+
fn start_ccp_multi<T: IntegrationTest + 'static + Send>(
104+
sks: Vec<Socket<Blocking>>,
105+
log: slog::Logger,
106+
tx: mpsc::Sender<Result<(), ()>>,
107+
) -> portus::CCPHandle {
108+
let b = MultiBackendBuilder { socks: sks };
109+
portus::spawn::<Socket<Blocking>, TestBaseConfig<T>, MultiBackendBuilder<Socket<Blocking>>>(
110+
b,
111+
portus::Config {
112+
logger: Some(log.clone()),
113+
},
114+
TestBaseConfig(tx, Some(log.clone()), PhantomData::<T>),
115+
)
116+
}
117+
103118
// Runs a specific intergration test
104-
pub fn run_test<T: IntegrationTest + 'static + Send>(log: slog::Logger, num_flows: usize) {
119+
pub fn run_test<T: IntegrationTest + 'static + Send>(
120+
log: slog::Logger,
121+
num_flows: usize,
122+
use_multi: bool,
123+
) {
105124
let (tx, rx) = std::sync::mpsc::channel();
106125

107126
// Channel for IPC
@@ -113,14 +132,17 @@ pub fn run_test<T: IntegrationTest + 'static + Send>(log: slog::Logger, num_flow
113132
let (dp_handle, conn_handles) = mock_datapath::start(dp_log, num_flows, s2, r1);
114133

115134
let sk = Socket::<Blocking>::new(s1, r2);
116-
let ccp_handle = start_ccp::<T>(sk, log.clone(), tx);
135+
let ccp_handle = match use_multi {
136+
false => start_ccp::<T>(sk, log.clone(), tx),
137+
true => start_ccp_multi::<T>(vec![sk], log.clone(), tx),
138+
};
117139

118140
// wait for program to finish
119141
let wait_for_done = thread::spawn(move || {
120142
rx.recv_timeout(std::time::Duration::from_secs(20))
121143
.unwrap()
122144
.unwrap();
123-
ccp_handle.kill(); // causes backend to stop iterating
145+
ccp_handle.kill();
124146
ccp_handle.wait().unwrap();
125147

126148
for h in conn_handles {

tests/preset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ impl IntegrationTest for TestPresetVars {
6969
fn preset() {
7070
let log = libccp_integration::logger();
7171
info!(log, "starting preset test");
72-
libccp_integration::run_test::<TestPresetVars>(log, 1);
72+
libccp_integration::run_test::<TestPresetVars>(log, 1, false);
7373
}

tests/timing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ impl IntegrationTest for TestTiming {
8383
fn timing() {
8484
let log = libccp_integration::logger();
8585
info!(log, "starting timing test");
86-
libccp_integration::run_test::<TestTiming>(log, 1);
86+
libccp_integration::run_test::<TestTiming>(log, 1, false);
8787
}

tests/twoflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ impl IntegrationTest for TestTwoFlows {
8888
fn twoflow() {
8989
let log = libccp_integration::logger();
9090
info!(log, "starting twoflow test");
91-
libccp_integration::run_test::<TestTwoFlows>(log, 2);
91+
libccp_integration::run_test::<TestTwoFlows>(log, 2, false);
9292
}

tests/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ impl IntegrationTest for TestUpdateFields {
8888
fn update() {
8989
let log = libccp_integration::logger();
9090
info!(log, "starting update test");
91-
libccp_integration::run_test::<TestUpdateFields>(log, 1);
91+
libccp_integration::run_test::<TestUpdateFields>(log, 1, false);
9292
}

tests/volatile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ impl IntegrationTest for TestVolatileVars {
7474
fn volatile() {
7575
let log = libccp_integration::logger();
7676
info!(log, "starting volatile test");
77-
libccp_integration::run_test::<TestVolatileVars>(log, 1);
77+
libccp_integration::run_test::<TestVolatileVars>(log, 1, false);
7878
}

0 commit comments

Comments
 (0)