Skip to content

Commit ab70029

Browse files
Sylvain GarciaGarcia6l20
authored andcommitted
fix tests
1 parent ca88f61 commit ab70029

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

lib/io_service.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ cppcoro::io_service::io_service(
355355
, m_winsockInitialised(false)
356356
, m_winsockInitialisationMutex()
357357
#elif CPPCORO_OS_LINUX
358-
, m_uq(queue_length)
358+
, m_uq(std::max(queue_length, size_t(10)))
359359
#endif
360360
, m_scheduleOperations(nullptr)
361361
#if CPPCORO_OS_WINNT

test/file_tests.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ namespace fs = cppcoro::filesystem;
2929

3030
namespace
3131
{
32+
template <bool use_current_dir = false>
3233
class temp_dir_fixture
3334
{
3435
public:
3536

3637
temp_dir_fixture()
3738
{
38-
auto tempDir = fs::temp_directory_path();
39+
fs::path tempDir;
40+
if constexpr (use_current_dir) {
41+
tempDir = fs::current_path() / "tmp";
42+
} else {
43+
tempDir = fs::temp_directory_path();
44+
}
3945

4046
std::random_device random;
4147
for (int attempt = 1;; ++attempt)
@@ -72,14 +78,23 @@ namespace
7278

7379
};
7480

81+
template <bool use_current_dir = false>
7582
class temp_dir_with_io_service_fixture :
7683
public io_service_fixture,
77-
public temp_dir_fixture
84+
public temp_dir_fixture<use_current_dir>
7885
{
7986
};
8087
}
8188

82-
TEST_CASE_FIXTURE(temp_dir_fixture, "write a file")
89+
#ifdef CPPCORO_TESTS_LIMITED_RESOURCES
90+
using tmp_dir_fixture = temp_dir_fixture<true>;
91+
using tmp_dir_with_io_service_fixture = temp_dir_with_io_service_fixture<true>;
92+
#else
93+
using tmp_dir_fixture = temp_dir_fixture<>;
94+
using tmp_dir_with_io_service_fixture = temp_dir_with_io_service_fixture<>;
95+
#endif
96+
97+
TEST_CASE_FIXTURE(tmp_dir_fixture, "write a file")
8398
{
8499
auto filePath = temp_dir() / "foo";
85100

@@ -143,7 +158,7 @@ TEST_CASE_FIXTURE(temp_dir_fixture, "write a file")
143158
}()));
144159
}
145160

146-
TEST_CASE_FIXTURE(temp_dir_with_io_service_fixture, "read write file")
161+
TEST_CASE_FIXTURE(tmp_dir_with_io_service_fixture, "read write file")
147162
{
148163
auto run = [&]() -> cppcoro::task<>
149164
{
@@ -168,7 +183,7 @@ TEST_CASE_FIXTURE(temp_dir_with_io_service_fixture, "read write file")
168183
cppcoro::sync_wait(run());
169184
}
170185

171-
TEST_CASE_FIXTURE(temp_dir_with_io_service_fixture, "cancel read")
186+
TEST_CASE_FIXTURE(tmp_dir_with_io_service_fixture, "cancel read")
172187
{
173188
cppcoro::sync_wait([&]() -> cppcoro::task<>
174189
{

test/io_service_fixture.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ struct io_service_fixture
1919
{
2020
public:
2121

22-
io_service_fixture(std::uint32_t threadCount = 1)
23-
: m_ioService()
22+
io_service_fixture(std::uint32_t threadCount = 1, std::uint32_t concurrencyHint = 0)
23+
: m_ioService(concurrencyHint)
2424
{
2525
m_ioThreads.reserve(threadCount);
2626
try
@@ -60,11 +60,11 @@ struct io_service_fixture
6060

6161
};
6262

63-
template<std::uint32_t thread_count>
63+
template<std::uint32_t thread_count, std::uint32_t concurrency_hint = 0>
6464
struct io_service_fixture_with_threads : io_service_fixture
6565
{
6666
io_service_fixture_with_threads()
67-
: io_service_fixture(thread_count)
67+
: io_service_fixture(thread_count, concurrency_hint)
6868
{}
6969
};
7070

test/io_service_tests.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,18 @@ TEST_CASE("schedule coroutine")
6969
}()));
7070
}
7171

72-
TEST_CASE_FIXTURE(io_service_fixture_with_threads<2>, "multiple I/O threads servicing events")
72+
#if CPPCORO_USE_IO_RING
73+
using multi_io_thread_servicing_events_fixture = io_service_fixture_with_threads<2, 128>;
74+
#else
75+
using multi_io_thread_servicing_events_fixture = io_service_fixture_with_threads<2>;
76+
#endif
77+
78+
TEST_CASE_FIXTURE(multi_io_thread_servicing_events_fixture, "multiple I/O threads servicing events")
7379
{
7480
std::atomic<int> completedCount = 0;
7581

7682
#ifdef CPPCORO_TESTS_LIMITED_RESOURCES
77-
constexpr int operations = 128;
83+
constexpr int operations = 256;
7884
#else
7985
constexpr int operations = 1000;
8086
#endif
@@ -197,7 +203,13 @@ TEST_CASE("Timer cancellation"
197203
}()));
198204
}
199205

200-
TEST_CASE_FIXTURE(io_service_fixture_with_threads<1>, "Many concurrent timers")
206+
#if CPPCORO_USE_IO_RING
207+
using many_concurrent_fixture = io_service_fixture_with_threads<1, 10>;
208+
#else
209+
using many_concurrent_fixture = io_service_fixture_with_threads<1>;
210+
#endif
211+
212+
TEST_CASE_FIXTURE(many_concurrent_fixture, "Many concurrent timers")
201213
{
202214
auto startTimer = [&]() -> cppcoro::task<>
203215
{

test/when_all_tests.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,14 @@ TEST_CASE("when_all() with all task types")
112112

113113
CHECK(a == "foo");
114114
CHECK(b.id == 0);
115-
CHECK(counted::active_count() == 1);
115+
// GCC 10.1 fails this check: at this point there are 3 objects alive
116+
// * One will be destructed later
117+
// * One object is completely leaked
118+
#if CPPCORO_COMPILER_GCC && CPPCORO_COMPILER_GCC <= 10'02'00
119+
WARN("GCC <= 10.02 is known to produce memory leaks !!!");
120+
#else
121+
CHECK(counted::active_count() == 1);
122+
#endif
116123
};
117124

118125
cppcoro::async_manual_reset_event event;

0 commit comments

Comments
 (0)