Skip to content

Commit b7b5197

Browse files
committed
test passed 3+ times locally.
1 parent 4a34644 commit b7b5197

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

src/sample.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,12 @@ factory::~factory() {
470470
while (cur) {
471471
sample *next = cur->next_.load();
472472

473-
// Only delete samples that are outside of storage area
474-
if (cur != sentinel() && (static_cast<void*>(cur) < storage_ ||
475-
static_cast<void*>(cur) >= storage_ + storage_size_))
473+
// Delete sample if it's not the sentinel and not in the storage area
474+
if (cur != sentinel() &&
475+
(reinterpret_cast<char*>(cur) < storage_ ||
476+
reinterpret_cast<char*>(cur) >= storage_ + storage_size_)) {
476477
delete cur;
477-
478+
}
478479
cur = next;
479480
}
480481
delete[] storage_;

testing/ext/bench_pushpull.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,53 @@ TEMPLATE_TEST_CASE("pushpull", "[basic][throughput]", char, double, std::string)
2727
lsl::channel_format_t cf = (lsl::channel_format_t)SampleType<TestType>::chan_fmt;
2828

2929
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());
3033
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));
3340
REQUIRE(!found_stream_info.empty());
3441

3542
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);
4154
}
55+
4256
std::string suffix(std::to_string(nchan) + "_inlets_" + std::to_string(n_inlets));
4357

4458
BENCHMARK("push_sample_nchan_" + suffix) {
4559
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();
4761
};
4862

4963
BENCHMARK("push_chunk_nchan_" + suffix) {
5064
out.push_chunk_multiplexed(data, chunk_size);
51-
for (auto &inlet : inlet_list) inlet.flush();
65+
for (auto &inlet : inlets) inlet->flush();
5266
};
5367

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();
5971
}
72+
inlets.clear();
6073

74+
// Give time for network cleanup between iterations
75+
std::this_thread::sleep_for(std::chrono::milliseconds(50));
6176
}
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-
// }
6777
}
6878
}
6979

0 commit comments

Comments
 (0)