From c2c9173eff9e929004d73e087b62ffdc25f0f4ee Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sat, 8 Oct 2022 01:05:19 -0700 Subject: Fix https://github.com/oven-sh/bun/issues/1263 What happened: when moving to uSockets for the http client, I forgot to call `SSL_set_tlsext_host_name` and uSockets apparently doesn't do that --- test/bun.js/fetch.test.js | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'test/bun.js/fetch.test.js') diff --git a/test/bun.js/fetch.test.js b/test/bun.js/fetch.test.js index 87d9e0576..1b9d0779e 100644 --- a/test/bun.js/fetch.test.js +++ b/test/bun.js/fetch.test.js @@ -2,6 +2,12 @@ import { it, describe, expect } from "bun:test"; import fs from "fs"; import { gc } from "./gc"; +const exampleFixture = fs.readFileSync( + import.meta.path.substring(0, import.meta.path.lastIndexOf("/")) + + "/fetch.js.txt", + "utf8" +); + describe("fetch", () => { const urls = ["https://example.com", "http://example.com"]; for (let url of urls) { @@ -12,17 +18,32 @@ describe("fetch", () => { gc(); const text = await response.text(); gc(); - expect( - fs.readFileSync( - import.meta.path.substring(0, import.meta.path.lastIndexOf("/")) + - "/fetch.js.txt", - "utf8" - ) - ).toBe(text); + expect(exampleFixture).toBe(text); }); } }); +it("simultaneous HTTPS fetch", async () => { + const urls = ["https://example.com", "https://www.example.com"]; + for (let batch = 0; batch < 4; batch++) { + const promises = new Array(20); + for (let i = 0; i < 20; i++) { + promises[i] = fetch(urls[i % 2]); + } + const result = await Promise.all(promises); + expect(result.length).toBe(20); + for (let i = 0; i < 20; i++) { + expect(result[i].status).toBe(200); + expect(await result[i].text()).toBe(exampleFixture); + } + } +}); + +it("website with tlsextname", async () => { + // irony + await fetch("https://bun.sh", { method: "HEAD" }); +}); + function testBlobInterface(blobbyConstructor, hasBlobFn) { for (let withGC of [false, true]) { for (let jsonObject of [ -- cgit v1.2.3