@@ -2291,6 +2291,106 @@ KJ_TEST("Server: Durable Objects websocket hibernation") {
2291
2291
wsConn.send (kj::str (" \x81\x1a " , confirmEviction));
2292
2292
wsConn.recvWebSocket (evicted);
2293
2293
}
2294
+
2295
+ KJ_TEST (" Server: tail workers" ) {
2296
+ TestServer test (R"( (
2297
+ services = [
2298
+ ( name = "hello",
2299
+ worker = (
2300
+ compatibilityDate = "2024-11-01",
2301
+ modules = [
2302
+ ( name = "main.js",
2303
+ esModule =
2304
+ `export default {
2305
+ ` async fetch(req, env, ctx) {
2306
+ ` console.log("foo", "bar");
2307
+ ` console.log("baz");
2308
+ ` return new Response("OK");
2309
+ ` }
2310
+ `}
2311
+ )
2312
+ ],
2313
+ logging = (
2314
+ toServices = ["tail", "tail2"]
2315
+ ),
2316
+ )
2317
+ ),
2318
+ ( name = "tail",
2319
+ worker = (
2320
+ compatibilityDate = "2024-11-01",
2321
+ modules = [
2322
+ ( name = "main.js",
2323
+ esModule =
2324
+ `export default {
2325
+ ` async tail(req, env, ctx) {
2326
+ ` await fetch("http://tail", {
2327
+ ` method: "POST",
2328
+ ` body: JSON.stringify(req[0].logs.map(log => log.message))
2329
+ ` });
2330
+ ` }
2331
+ `}
2332
+ )
2333
+ ],
2334
+ )
2335
+ ),
2336
+ ( name = "tail2",
2337
+ worker = (
2338
+ compatibilityDate = "2024-11-01",
2339
+ modules = [
2340
+ ( name = "main.js",
2341
+ esModule =
2342
+ `export default {
2343
+ ` async tail(req, env, ctx) {
2344
+ ` await fetch("http://tail2/" + req[0].logs.length);
2345
+ ` }
2346
+ `}
2347
+ )
2348
+ ],
2349
+ )
2350
+ ),
2351
+ ],
2352
+ sockets = [
2353
+ ( name = "main",
2354
+ address = "test-addr",
2355
+ service = "hello"
2356
+ )
2357
+ ]
2358
+ ))" _kj);
2359
+
2360
+ test.start ();
2361
+ auto conn = test.connect (" test-addr" );
2362
+ conn.sendHttpGet (" /" );
2363
+ conn.recvHttp200 (" OK" );
2364
+
2365
+ auto subreq = test.receiveInternetSubrequest (" tail" );
2366
+ subreq.recv (R"(
2367
+ POST / HTTP/1.1
2368
+ Content-Length: 23
2369
+ Host: tail
2370
+ Content-Type: text/plain;charset=UTF-8
2371
+
2372
+ [["foo","bar"],["baz"]])" _blockquote);
2373
+
2374
+ auto subreq2 = test.receiveInternetSubrequest (" tail2" );
2375
+ subreq2.recv (R"(
2376
+ GET /2 HTTP/1.1
2377
+ Host: tail2
2378
+
2379
+ )" _blockquote);
2380
+
2381
+ subreq.send (R"(
2382
+ HTTP/1.1 200 OK
2383
+ Content-Length: 0
2384
+
2385
+ )" _blockquote);
2386
+
2387
+ subreq2.send (R"(
2388
+ HTTP/1.1 200 OK
2389
+ Content-Length: 0
2390
+
2391
+ )" _blockquote);
2392
+ }
2393
+
2294
2394
// =======================================================================================
2295
2395
// Test HttpOptions on receive
2296
2396
0 commit comments