| 257 | } |
| 258 | |
| 259 | static void *frontend_eof_writer(void *opaque) { |
| 260 | frontend_eof_writer_t *writer = opaque; |
| 261 | static const char first[] = |
| 262 | "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"test/block\",\"params\":{}}\n"; |
| 263 | bool ok = frontend_eof_write_all(writer->fd, first, sizeof(first) - 1); |
| 264 | uint64_t deadline = cbm_now_ms() + FRONTEND_EOF_TEST_REQUEST_TIMEOUT_MS; |
| 265 | while ( |
| 266 | ok && |
| 267 | !atomic_load_explicit(&writer->application->first_request_started, memory_order_acquire) && |
| 268 | cbm_now_ms() < deadline) { |
| 269 | cbm_usleep(1000); |
| 270 | } |
| 271 | ok = ok && |
| 272 | atomic_load_explicit(&writer->application->first_request_started, memory_order_acquire); |
| 273 | for (int index = 0; ok && writer->overflow && index < FRONTEND_EOF_TEST_OVERFLOW_MESSAGES; |
| 274 | index++) { |
| 275 | char message[160]; |
| 276 | int written = |
| 277 | snprintf(message, sizeof(message), |
| 278 | "{\"jsonrpc\":\"2.0\",\"id\":%d,\"method\":\"test/queued\",\"params\":{}}\n", |
| 279 | index + 2); |
| 280 | ok = written > 0 && written < (int)sizeof(message) && |
| 281 | frontend_eof_write_all(writer->fd, message, (size_t)written); |
| 282 | } |
| 283 | ok = close(writer->fd) == 0 && ok; |
| 284 | writer->fd = -1; |
| 285 | if (writer->overflow) { |
| 286 | /* Everything — 32 over-capacity frames AND the EOF behind them — is now |
| 287 | * committed to the pipe. Only now release the held first request: the |
| 288 | * queue was provably full while it blocked, so the drain that follows |
| 289 | * exercises enqueue-wait, not a conveniently fast worker. */ |
| 290 | atomic_store_explicit(&writer->application->release_first_request, true, |
| 291 | memory_order_release); |
| 292 | } |
| 293 | atomic_store_explicit(&writer->succeeded, ok, memory_order_release); |
| 294 | atomic_store_explicit(&writer->finished, true, memory_order_release); |
| 295 | return NULL; |
| 296 | } |
| 297 | |
| 298 | static bool frontend_eof_fixture_start(frontend_eof_fixture_t *fixture, const char *parent) { |
| 299 | memset(fixture, 0, sizeof(*fixture)); |
nothing calls this directly
no test coverage detected