@@ -27,43 +27,53 @@ TEMPLATE_TEST_CASE("pushpull", "[basic][throughput]", char, double, std::string)
27
27
lsl::channel_format_t cf = (lsl::channel_format_t )SampleType<TestType>::chan_fmt;
28
28
29
29
for (auto nchan : param_nchan) {
30
+ // Create outlet with a unique name for each test iteration
31
+ std::string unique_name = std::string (name) + " _" + std::to_string (nchan) + " _" +
32
+ std::to_string (std::chrono::steady_clock::now ().time_since_epoch ().count ());
30
33
lsl::stream_outlet out (
31
- lsl::stream_info (name, " PushPull" , (int )nchan, chunk_size, cf, " streamid" ));
32
- auto found_stream_info (lsl::resolve_stream (" name" , name, 1 , 2.0 ));
34
+ lsl::stream_info (unique_name, " PushPull" , (int )nchan, chunk_size, cf, " streamid" ));
35
+
36
+ // Wait for outlet to be discoverable
37
+ std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
38
+
39
+ auto found_stream_info (lsl::resolve_stream (" name" , unique_name, 1 , 2.0 ));
33
40
REQUIRE (!found_stream_info.empty ());
34
41
35
42
for (auto n_inlets : param_inlets) {
36
- std::list<lsl::stream_inlet> inlet_list;
37
- while (inlet_list.size () < n_inlets) {
38
- lsl::stream_info info_copy (found_stream_info[0 ]);
39
- inlet_list.emplace_front (info_copy, 300 , false );
40
- inlet_list.front ().open_stream (.5 );
43
+ std::vector<std::unique_ptr<lsl::stream_inlet>> inlets;
44
+
45
+ // Create inlets
46
+ for (std::size_t i = 0 ; i < n_inlets; ++i) {
47
+ inlets.emplace_back (std::make_unique<lsl::stream_inlet>(found_stream_info[0 ], 300 , false ));
48
+ inlets.back ()->open_stream (.5 );
49
+ }
50
+
51
+ // Wait for consumers to connect
52
+ if (n_inlets > 0 ) {
53
+ out.wait_for_consumers (1.0 );
41
54
}
55
+
42
56
std::string suffix (std::to_string (nchan) + " _inlets_" + std::to_string (n_inlets));
43
57
44
58
BENCHMARK (" push_sample_nchan_" + suffix) {
45
59
for (size_t s = 0 ; s < chunk_size; s++) out.push_sample (data);
46
- for (auto &inlet : inlet_list ) inlet. flush ();
60
+ for (auto &inlet : inlets ) inlet-> flush ();
47
61
};
48
62
49
63
BENCHMARK (" push_chunk_nchan_" + suffix) {
50
64
out.push_chunk_multiplexed (data, chunk_size);
51
- for (auto &inlet : inlet_list ) inlet. flush ();
65
+ for (auto &inlet : inlets ) inlet-> flush ();
52
66
};
53
67
54
- // Explicitly close and delete the inlets to ensure that they are not
55
- // still in use when the next inlet is created.
56
- for (int i = 0 ; i < n_inlets; i++) {
57
- inlet_list.back ().close_stream ();
58
- inlet_list.pop_back ();
68
+ // Explicitly close inlets and wait for cleanup
69
+ for (auto &inlet : inlets) {
70
+ inlet->close_stream ();
59
71
}
72
+ inlets.clear ();
60
73
74
+ // Give time for network cleanup between iterations
75
+ std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
61
76
}
62
- // Wait until all inlets are closed
63
- // this hangs forever
64
- // while (out.have_consumers()) {
65
- // std::this_thread::sleep_for(std::chrono::milliseconds(1));
66
- // }
67
77
}
68
78
}
69
79
0 commit comments