diff options
author | 2022-09-22 02:25:32 -0700 | |
---|---|---|
committer | 2022-09-22 02:25:32 -0700 | |
commit | ce9daa48572a345ffd95e41d9f64b9e4719a88fa (patch) | |
tree | d3a6198f4c17e4afe3edb403efc9eea08212a589 /test/bun.js | |
parent | e15fb6b9b220510df049e782d4f2f6eb3150d069 (diff) | |
download | bun-ce9daa48572a345ffd95e41d9f64b9e4719a88fa.tar.gz bun-ce9daa48572a345ffd95e41d9f64b9e4719a88fa.tar.zst bun-ce9daa48572a345ffd95e41d9f64b9e4719a88fa.zip |
1 event loop per thread. Instead of 3.
uWebSockets and uSockets will need to be upgraded to match the changes.
Previously:
- Bun had a separate kqueue/eventfd just for async wakeups.
- Bun had a separate kqueue/epoll just for reading files non-blocking in the same thread
This commit unifies it into one event loop per thread
Diffstat (limited to 'test/bun.js')
-rw-r--r-- | test/bun.js/ffi.test.fixture.callback.c | 35 | ||||
-rw-r--r-- | test/bun.js/ffi.test.fixture.receiver.c | 35 | ||||
-rw-r--r-- | test/bun.js/serve.test.ts | 56 |
3 files changed, 81 insertions, 45 deletions
diff --git a/test/bun.js/ffi.test.fixture.callback.c b/test/bun.js/ffi.test.fixture.callback.c index 7de63120f..cb38eebe8 100644 --- a/test/bun.js/ffi.test.fixture.callback.c +++ b/test/bun.js/ffi.test.fixture.callback.c @@ -147,23 +147,39 @@ static bool JSVALUE_IS_NUMBER(EncodedJSValue val) { } +// JSValue numbers-as-pointers are represented as a 52-bit integer +// Previously, the pointer was stored at the end of the 64-bit value +// Now, they're stored at the beginning of the 64-bit value +// This behavior change enables the JIT to handle it better +// It also is better readability when console.log(myPtr) static void* JSVALUE_TO_PTR(EncodedJSValue val) { - // must be a double if (val.asInt64 == TagValueNull) return 0; - return (void*)(val.asInt64 - DoubleEncodeOffset); + val.asInt64 -= DoubleEncodeOffset; + size_t ptr = (size_t)val.asDouble; + return (void*)ptr; } static EncodedJSValue PTR_TO_JSVALUE(void* ptr) { EncodedJSValue val; - if (ptr == 0) { - val.asInt64 = TagValueNull; - return val; + if (ptr == 0) + { + val.asInt64 = TagValueNull; + return val; } - val.asInt64 = (int64_t)ptr + DoubleEncodeOffset; + + val.asDouble = (double)(size_t)ptr; + val.asInt64 += DoubleEncodeOffset; return val; } +static EncodedJSValue DOUBLE_TO_JSVALUE(double val) { + EncodedJSValue res; + res.asDouble = val; + res.asInt64 += DoubleEncodeOffset; + return res; +} + static int32_t JSVALUE_TO_INT32(EncodedJSValue val) { return val.asInt64; } @@ -175,12 +191,7 @@ static EncodedJSValue INT32_TO_JSVALUE(int32_t val) { } -static EncodedJSValue DOUBLE_TO_JSVALUE(double val) { - EncodedJSValue res; - res.asDouble = val; - res.asInt64 += DoubleEncodeOffset; - return res; -} + static EncodedJSValue FLOAT_TO_JSVALUE(float val) { return DOUBLE_TO_JSVALUE((double)val); diff --git a/test/bun.js/ffi.test.fixture.receiver.c b/test/bun.js/ffi.test.fixture.receiver.c index 550d64b81..f8417805d 100644 --- a/test/bun.js/ffi.test.fixture.receiver.c +++ b/test/bun.js/ffi.test.fixture.receiver.c @@ -148,23 +148,39 @@ static bool JSVALUE_IS_NUMBER(EncodedJSValue val) { } +// JSValue numbers-as-pointers are represented as a 52-bit integer +// Previously, the pointer was stored at the end of the 64-bit value +// Now, they're stored at the beginning of the 64-bit value +// This behavior change enables the JIT to handle it better +// It also is better readability when console.log(myPtr) static void* JSVALUE_TO_PTR(EncodedJSValue val) { - // must be a double if (val.asInt64 == TagValueNull) return 0; - return (void*)(val.asInt64 - DoubleEncodeOffset); + val.asInt64 -= DoubleEncodeOffset; + size_t ptr = (size_t)val.asDouble; + return (void*)ptr; } static EncodedJSValue PTR_TO_JSVALUE(void* ptr) { EncodedJSValue val; - if (ptr == 0) { - val.asInt64 = TagValueNull; - return val; + if (ptr == 0) + { + val.asInt64 = TagValueNull; + return val; } - val.asInt64 = (int64_t)ptr + DoubleEncodeOffset; + + val.asDouble = (double)(size_t)ptr; + val.asInt64 += DoubleEncodeOffset; return val; } +static EncodedJSValue DOUBLE_TO_JSVALUE(double val) { + EncodedJSValue res; + res.asDouble = val; + res.asInt64 += DoubleEncodeOffset; + return res; +} + static int32_t JSVALUE_TO_INT32(EncodedJSValue val) { return val.asInt64; } @@ -176,12 +192,7 @@ static EncodedJSValue INT32_TO_JSVALUE(int32_t val) { } -static EncodedJSValue DOUBLE_TO_JSVALUE(double val) { - EncodedJSValue res; - res.asDouble = val; - res.asInt64 += DoubleEncodeOffset; - return res; -} + static EncodedJSValue FLOAT_TO_JSVALUE(float val) { return DOUBLE_TO_JSVALUE((double)val); diff --git a/test/bun.js/serve.test.ts b/test/bun.js/serve.test.ts index 95428c028..317d94100 100644 --- a/test/bun.js/serve.test.ts +++ b/test/bun.js/serve.test.ts @@ -39,7 +39,9 @@ describe("streaming", () => { }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch( + `http://${server.hostname}:${server.port}` + ); if (response.status > 0) { expect(response.status).toBe(500); expect(await response.text()).toBe("fail"); @@ -77,7 +79,9 @@ describe("streaming", () => { }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch( + `http://${server.hostname}:${server.port}` + ); // connection terminated if (response.status > 0) { expect(response.status).toBe(200); @@ -110,7 +114,7 @@ describe("streaming", () => { }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); const text = await response.text(); expect(text.length).toBe(textToExpect.length); expect(text).toBe(textToExpect); @@ -134,7 +138,7 @@ describe("streaming", () => { ); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); server.stop(); }); @@ -157,8 +161,18 @@ describe("streaming", () => { }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); - expect(response.status).toBe(500); + var response; + try { + response = await fetch(`http://${server.hostname}:${server.port}`); + } catch (e) { + if (e.name !== "ConnectionClosed") { + throw e; + } + } + + if (response) { + expect(response.status).toBe(500); + } } catch (e) { if (!e || !(e instanceof TestPass)) { throw e; @@ -191,7 +205,7 @@ describe("streaming", () => { }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(response.status).toBe(500); expect(await response.text()).toBe("Fail"); expect(pass).toBe(true); @@ -222,7 +236,7 @@ describe("streaming", () => { ); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); server.stop(); }); @@ -244,7 +258,7 @@ describe("streaming", () => { ); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); const text = await response.text(); expect(text).toBe(textToExpect); server.stop(); @@ -270,7 +284,7 @@ describe("streaming", () => { ); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); server.stop(); }); @@ -295,7 +309,7 @@ describe("streaming", () => { ); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); server.stop(); }); @@ -324,7 +338,7 @@ describe("streaming", () => { ); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); server.stop(); }); @@ -337,7 +351,7 @@ it("should work for a hello world", async () => { return new Response(`Hello, world!`); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe("Hello, world!"); server.stop(); }); @@ -352,7 +366,7 @@ it("should work for a blob", async () => { return new Response(new Blob([textToExpect])); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); server.stop(); }); @@ -367,7 +381,7 @@ it("should work for a blob stream", async () => { return new Response(new Blob([textToExpect]).stream()); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); server.stop(); }); @@ -382,7 +396,7 @@ it("should work for a file", async () => { return new Response(file(fixture)); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); server.stop(); }); @@ -397,7 +411,7 @@ it("should work for a file stream", async () => { return new Response(file(fixture).stream()); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); server.stop(); }); @@ -416,7 +430,7 @@ it("fetch should work with headers", async () => { }); }, }); - const response = await fetch(`http://127.0.0.1:${server.port}`, { + const response = await fetch(`http://${server.hostname}:${server.port}`, { headers: { "X-Foo": "bar", }, @@ -444,7 +458,7 @@ it(`should work for a file ${count} times serial`, async () => { // it's hard to say if this only happens here due to some weird stuff with the test runner // or if it's "real" issue for (let i = 0; i < count; i++) { - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); } @@ -467,7 +481,7 @@ it(`should work for text ${count} times serial`, async () => { // it's hard to say if this only happens here due to some weird stuff with the test runner // or if it's "real" issue for (let i = 0; i < count; i++) { - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); } @@ -488,7 +502,7 @@ it(`should work for ArrayBuffer ${count} times serial`, async () => { // it's hard to say if this only happens here due to some weird stuff with the test runner // or if it's "real" issue for (let i = 0; i < count; i++) { - const response = await fetch(`http://127.0.0.1:${server.port}`); + const response = await fetch(`http://${server.hostname}:${server.port}`); expect(await response.text()).toBe(textToExpect); } |