Skip to content

Commit

Permalink
fix(userspace/libsinsp): solve test issues with emscripten and windows
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce authored and poiana committed Nov 18, 2023
1 parent e19b113 commit 60e5b74
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions userspace/libsinsp/test/mpsc_priority_queue.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ limitations under the License.
#include "mpsc_priority_queue.h"
#include <gtest/gtest.h>
#include <thread>
#include <chrono>

using val_t = std::unique_ptr<int>;

// note: emscripten does not support launching threads
#ifndef __EMSCRIPTEN__

TEST(mpsc_priority_queue, single_producer)
{
const int max_value = 1000;
Expand All @@ -31,6 +35,7 @@ TEST(mpsc_priority_queue, single_producer)
auto p = std::thread([&](){
for (int i = 0; i < max_value; i++)
{
std::this_thread::sleep_for(std::chrono::microseconds(100));
q.push(std::make_unique<int>(i));
}
});
Expand All @@ -41,6 +46,7 @@ TEST(mpsc_priority_queue, single_producer)
int failed = 0;
while (i < max_value)
{
std::this_thread::sleep_for(std::chrono::microseconds(100));
if (q.empty())
{
continue;
Expand All @@ -63,12 +69,10 @@ TEST(mpsc_priority_queue, single_producer)
ASSERT_EQ(failed, 0);
}

// note: emscripten does not support multi-threading
#ifndef __EMSCRIPTEN__
TEST(mpsc_priority_queue, multi_producer)
{
const int num_values = 1000;
const int num_producers = 20;
const int num_producers = 10;
mpsc_priority_queue<val_t, std::greater_equal<int>> q;
std::atomic<int> counter{1};

Expand All @@ -79,6 +83,7 @@ TEST(mpsc_priority_queue, multi_producer)
producers.emplace_back([&](){
for (int i = 0; i <= num_values; i++)
{
std::this_thread::sleep_for(std::chrono::microseconds(100));
q.push(std::make_unique<int>(counter++));
}
});
Expand All @@ -91,6 +96,7 @@ TEST(mpsc_priority_queue, multi_producer)
int last_val = 0;
while (i < num_values * num_producers)
{
std::this_thread::sleep_for(std::chrono::microseconds(100));
if (q.empty())
{
continue;
Expand All @@ -115,4 +121,5 @@ TEST(mpsc_priority_queue, multi_producer)
// check we received everything in order
ASSERT_EQ(failed, 0);
}

#endif // __EMSCRIPTEN__

0 comments on commit 60e5b74

Please sign in to comment.