Test for failures to handle EINTR during TLS connection negotiation and data send/receive.
| 216 | // Test for failures to handle EINTR during TLS connection |
| 217 | // negotiation and data send/receive. |
| 218 | TEST_F(TlsSocketTest, TestTlsSocketInterrupted) { |
| 219 | // Set up a no-op signal handler for SIGUSR2. |
| 220 | struct sigaction sa, sa_old; |
| 221 | memset(&sa, 0, sizeof(sa)); |
| 222 | sa.sa_handler = &handler; |
| 223 | sigaction(SIGUSR2, &sa, &sa_old); |
| 224 | SCOPED_CLEANUP({ sigaction(SIGUSR2, &sa_old, nullptr); }); |
| 225 | |
| 226 | EchoServer server; |
| 227 | NO_FATALS(server.Start()); |
| 228 | |
| 229 | // Start a thread to send signals to the server thread. |
| 230 | thread killer([&]() { |
| 231 | while (!server.stopped()) { |
| 232 | PCHECK(pthread_kill(server.pthread(), SIGUSR2) == 0); |
| 233 | SleepFor(MonoDelta::FromMicroseconds(rand() % 10)); |
| 234 | } |
| 235 | }); |
| 236 | SCOPED_CLEANUP({ killer.join(); }); |
| 237 | |
| 238 | unique_ptr<Socket> client_sock; |
| 239 | NO_FATALS(ConnectClient(server.listen_addr(), &client_sock)); |
| 240 | |
| 241 | unique_ptr<uint8_t[]> buf(new uint8_t[kEchoChunkSize]); |
| 242 | for (int i = 0; i < 10; i++) { |
| 243 | SleepFor(MonoDelta::FromMilliseconds(1)); |
| 244 | size_t nwritten; |
| 245 | ASSERT_OK(client_sock->BlockingWrite(buf.get(), kEchoChunkSize, &nwritten, |
| 246 | MonoTime::Now() + kTimeout)); |
| 247 | size_t n; |
| 248 | ASSERT_OK(client_sock->BlockingRecv(buf.get(), kEchoChunkSize, &n, |
| 249 | MonoTime::Now() + kTimeout)); |
| 250 | } |
| 251 | server.Stop(); |
| 252 | ASSERT_OK(client_sock->Close()); |
| 253 | LOG(INFO) << "client done"; |
| 254 | } |
| 255 | |
| 256 | // Return an iovec containing the same data as the buffer 'buf' with the length 'len', |
| 257 | // but split into random-sized chunks. The chunks are sized randomly between 1 and |
nothing calls this directly
no test coverage detected