File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,18 @@ public:
114114 " Env must either be empty or null-terminated!" );
115115 }
116116
117+ ~Task () {
118+ // Ensure pipes are closed when the task is destroyed
119+ if (Pipe >= 0 ) {
120+ close (Pipe);
121+ Pipe = -1 ;
122+ }
123+ if (ErrorPipe >= 0 ) {
124+ close (ErrorPipe);
125+ ErrorPipe = -1 ;
126+ }
127+ }
128+
117129 const char *getExecPath () const { return ExecPath; }
118130 ArrayRef<const char *> getArgs () const { return Args; }
119131 StringRef getOutput () const { return Output; }
Original file line number Diff line number Diff line change 1818
1919#include < algorithm>
2020#include < chrono>
21+ #include < condition_variable>
2122#include < mutex>
2223#include < thread>
2324
@@ -93,9 +94,15 @@ TEST(TaskQueueTest, TaskSignalHandling) {
9394 bool TaskSignalled = false ;
9495 int ReceivedSignal = 0 ;
9596 ProcessId ChildPid = 0 ;
97+ std::mutex PidMutex;
98+ std::condition_variable PidCv;
9699
97100 auto TaskBegan = [&](ProcessId Pid, void *Context) {
98- ChildPid = Pid;
101+ {
102+ std::lock_guard<std::mutex> lock (PidMutex);
103+ ChildPid = Pid;
104+ }
105+ PidCv.notify_one ();
99106 };
100107
101108 auto TaskSignalledCallback = [&](ProcessId Pid, llvm::StringRef ErrorMsg,
@@ -117,7 +124,11 @@ TEST(TaskQueueTest, TaskSignalHandling) {
117124 TQ.execute (TaskBegan, nullptr , TaskSignalledCallback);
118125 });
119126
120- std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
127+ // Wait for the task to actually start and get its PID
128+ {
129+ std::unique_lock<std::mutex> lock (PidMutex);
130+ PidCv.wait_for (lock, std::chrono::seconds (5 ), [&] { return ChildPid > 0 ; });
131+ }
121132
122133 if (ChildPid > 0 ) {
123134 EXPECT_EQ (0 , kill (ChildPid, SIGTERM)) << " Should kill the specific child process we spawned" ;
You can’t perform that action at this time.
0 commit comments