Skip to content

Commit 2ca79bb

Browse files
committed
Async: Test synchronous pipe reads from ThreadPool
1 parent 6011829 commit 2ca79bb

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

Tests/Libraries/Async/AsyncTest.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ SC::AsyncTest::AsyncTest(SC::TestReport& report) : TestCase(report, "AsyncTest")
6868
}
6969
if (test_section("process input output"))
7070
{
71-
processInputOutput();
71+
processInputOutput(false);
72+
}
73+
if (test_section("process input output threadpool"))
74+
{
75+
processInputOutput(true);
7276
}
7377
if (test_section("socket TCP accept"))
7478
{

Tests/Libraries/Async/AsyncTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct SC::AsyncTest : public SC::TestCase
3535

3636
// Processes
3737
void processExit();
38-
void processInputOutput();
38+
void processInputOutput(bool useThreadPool);
3939
void processInputOutputChild();
4040

4141
// Files

Tests/Libraries/Async/AsyncTestProcess.inl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,19 @@ void SC::AsyncTest::processExit()
5353
SC_TEST_EXPECT(outParams2.exitStatus != 0); // Status == Not OK
5454
}
5555

56-
void SC::AsyncTest::processInputOutput()
56+
void SC::AsyncTest::processInputOutput(bool useThreadPool)
5757
{
5858
StringSpan params[] = {report.executableFile, "--quiet", "--test",
5959
"AsyncTest", "--test-section", "process input output child"};
60-
60+
ThreadPool threadPool;
61+
if (useThreadPool)
62+
{
63+
SC_TEST_EXPECT(threadPool.create(1));
64+
}
6165
PipeDescriptor processStdOut;
6266
PipeOptions pipeOptions;
6367

64-
pipeOptions.blocking = true;
68+
pipeOptions.blocking = useThreadPool;
6569
pipeOptions.writeInheritable = true;
6670
SC_TEST_EXPECT(processStdOut.createPipe(pipeOptions));
6771
AsyncEventLoop eventLoop;
@@ -84,8 +88,14 @@ void SC::AsyncTest::processInputOutput()
8488
}
8589
};
8690
AsyncTaskSequence asyncReadTask;
87-
SC_TEST_EXPECT(eventLoop.associateExternallyCreatedFileDescriptor(processStdOut.readPipe));
88-
91+
if (useThreadPool)
92+
{
93+
SC_TEST_EXPECT(asyncRead.executeOn(asyncReadTask, threadPool));
94+
}
95+
else
96+
{
97+
SC_TEST_EXPECT(eventLoop.associateExternallyCreatedFileDescriptor(processStdOut.readPipe));
98+
}
8999
SC_TEST_EXPECT(processStdOut.readPipe.get(asyncRead.handle, Result::Error("handle")));
90100
char myBuffer[4]; // just enough to hold "asdf";
91101
asyncRead.buffer = myBuffer;

0 commit comments

Comments
 (0)