TEST_F(TCPConnectionTest, killServerDuringWrite) {
pid_t childProcessID;
switch (childProcessID = fork()) {
case -1: break;
case 0: {
// this process should be in a loop when the other process kills it
// otherwise, I want to the test to fail when it hits the next line
FAIL() << "Test is not written properly. Shouldn't get here. Should still be writing.";
break;
}
default: {
// do some stuff first
kill(childProcessID, SIGKILL);
int status;
pid_t result = waitpid(childProcessID, &status, WNOHANG);
while (result <= 0) result = waitpid(childProcessID, &status, WNOHANG);
printf("Another child MURDERED! Kids are idiots!\n");
EXPECT_GT(result, 0);
// some other tasks here
}
}
}
The problem here is that the test still passes, even though the FAIL() line is reached.
See terminal output:
tcptests.cpp:722: Failure
Failed
Test is not written properly. Shouldn't get here. Should still be writing.
Another child MURDERED! Kids are idiots!
[ OK ] TCPConnectionTest.killServerDuringWrite (64 ms)
[----------] 1 test from TCPConnectionTest (64 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (64 ms total)
[ PASSED ] 1 test.
The child process explicitly reports a failure which is seen in the terminal output, but is then killed. In the parent process, the rest of the test passes when the child is dead.
Is it possible that killing the child process before it returns prevents gtest from capturing the failure, even though it is seen in the terminal output?
Is this a limitation of the framework or am I not using the framework properly? Is this where death tests come into play?
Aucun commentaire:
Enregistrer un commentaire