mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 13:22:07 +00:00
windows: fix some websocket tests (#8433)
* windows: fix some websocket tests * this file should work now, report any errors * make this change later * add back running this with node * add as const to these --------- Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
@@ -14,4 +14,4 @@ Set-Content $Script2 -Force -NoNewline -Value $CreateHashTable
|
||||
Remove-Item -Path "build-release/codegen" -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Remove-Item -Path "build-release/js" -Recurse -Force -ErrorAction SilentlyContinue
|
||||
Copy-Item -Path "build/codegen" -Destination "build-release/codegen" -Recurse -Force
|
||||
Copy-Item -Path "build/js" -Destination "build-release/js" -Recurse -Force
|
||||
Copy-Item -Path "build/js" -Destination "build-release/js" -Recurse -Force
|
||||
|
||||
@@ -503,6 +503,7 @@ ExceptionOr<void> WebSocket::send(ArrayBuffer& binaryData)
|
||||
}
|
||||
char* data = static_cast<char*>(binaryData.data());
|
||||
size_t length = binaryData.byteLength();
|
||||
|
||||
this->sendWebSocketData(data, length, Opcode::Binary);
|
||||
|
||||
return {};
|
||||
|
||||
@@ -2413,6 +2413,7 @@ pub const PING: i32 = 9;
|
||||
pub const PONG: i32 = 10;
|
||||
|
||||
pub const Opcode = enum(i32) {
|
||||
continuation = 0,
|
||||
text = 1,
|
||||
binary = 2,
|
||||
close = 8,
|
||||
|
||||
@@ -214,18 +214,7 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type {
|
||||
|
||||
const HTTPClient = @This();
|
||||
|
||||
pub fn register(global: *JSC.JSGlobalObject, loop_: *anyopaque, ctx_: *anyopaque) callconv(.C) void {
|
||||
var vm = global.bunVM();
|
||||
const loop: *bun.Async.Loop = @alignCast(@ptrCast(loop_));
|
||||
const ctx: *uws.SocketContext = @as(*uws.SocketContext, @ptrCast(ctx_));
|
||||
|
||||
if (vm.event_loop_handle) |other| {
|
||||
std.debug.assert(other == loop);
|
||||
}
|
||||
const is_new_loop = vm.event_loop_handle == null;
|
||||
|
||||
vm.event_loop_handle = loop;
|
||||
|
||||
pub fn register(_: *JSC.JSGlobalObject, _: *anyopaque, ctx: *uws.SocketContext) callconv(.C) void {
|
||||
Socket.configure(
|
||||
ctx,
|
||||
true,
|
||||
@@ -242,9 +231,6 @@ pub fn NewHTTPUpgradeClient(comptime ssl: bool) type {
|
||||
pub const onHandshake = handleHandshake;
|
||||
},
|
||||
);
|
||||
if (is_new_loop) {
|
||||
vm.prepareLoop();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn connect(
|
||||
@@ -1636,12 +1622,12 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
|
||||
len: usize,
|
||||
op: u8,
|
||||
) callconv(.C) void {
|
||||
if (this.tcp.isClosed() or this.tcp.isShutdown()) {
|
||||
if (this.tcp.isClosed() or this.tcp.isShutdown() or op > 0xF) {
|
||||
this.dispatchAbruptClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const opcode = @as(Opcode, @enumFromInt(@as(u4, @truncate(op))));
|
||||
const opcode: Opcode = @enumFromInt(op);
|
||||
const slice = ptr[0..len];
|
||||
const bytes = Copy{ .bytes = slice };
|
||||
// fast path: small frame, no backpressure, attempt to send without allocating
|
||||
@@ -1655,6 +1641,7 @@ pub fn NewWebSocketClient(comptime ssl: bool) type {
|
||||
|
||||
_ = this.sendData(bytes, !this.hasBackpressure(), opcode);
|
||||
}
|
||||
|
||||
pub fn writeString(
|
||||
this: *WebSocket,
|
||||
str_: *const JSC.ZigString,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// @known-failing-on-windows: 1 failing
|
||||
import { describe, it, expect, afterEach } from "bun:test";
|
||||
import type { Server, Subprocess, WebSocketHandler } from "bun";
|
||||
import { serve, spawn } from "bun";
|
||||
import { bunEnv, bunExe, nodeExe } from "harness";
|
||||
import { isIP } from "node:net";
|
||||
import path from "node:path";
|
||||
|
||||
const strings = [
|
||||
{
|
||||
label: "string (ascii)",
|
||||
@@ -20,7 +21,7 @@ const strings = [
|
||||
message: "utf8-😶",
|
||||
bytes: [0x75, 0x74, 0x66, 0x38, 0x2d, 0xf0, 0x9f, 0x98, 0xb6],
|
||||
},
|
||||
];
|
||||
] as const;
|
||||
|
||||
const buffers = [
|
||||
{
|
||||
@@ -38,9 +39,9 @@ const buffers = [
|
||||
message: Buffer.from("utf8-🤩"),
|
||||
bytes: [0x75, 0x74, 0x66, 0x38, 0x2d, 0xf0, 0x9f, 0xa4, 0xa9],
|
||||
},
|
||||
];
|
||||
] as const;
|
||||
|
||||
const messages = [...strings, ...buffers];
|
||||
const messages = [...strings, ...buffers] as const;
|
||||
|
||||
const binaryTypes = [
|
||||
{
|
||||
@@ -590,14 +591,13 @@ function test(
|
||||
|
||||
async function connect(server: Server): Promise<void> {
|
||||
const url = new URL(`ws://${server.hostname}:${server.port}/`);
|
||||
const { pathname } = new URL("./websocket-client-echo.mjs", import.meta.url);
|
||||
const pathname = path.resolve(import.meta.dir, "./websocket-client-echo.mjs");
|
||||
// @ts-ignore
|
||||
const client = spawn({
|
||||
cmd: [nodeExe() ?? bunExe(), pathname, url],
|
||||
cwd: import.meta.dir,
|
||||
env: bunEnv,
|
||||
stderr: "ignore",
|
||||
stdout: "pipe",
|
||||
stdio: ["pipe", "pipe", "ignore"],
|
||||
});
|
||||
clients.push(client);
|
||||
for await (const chunk of client.stdout) {
|
||||
|
||||
@@ -21,7 +21,7 @@ const strings = [
|
||||
message: "utf8-😶",
|
||||
bytes: [0x75, 0x74, 0x66, 0x38, 0x2d, 0xf0, 0x9f, 0x98, 0xb6],
|
||||
},
|
||||
];
|
||||
] as const;
|
||||
|
||||
const buffers = [
|
||||
{
|
||||
@@ -39,9 +39,9 @@ const buffers = [
|
||||
message: Buffer.from("utf8-🤩"),
|
||||
bytes: [0x75, 0x74, 0x66, 0x38, 0x2d, 0xf0, 0x9f, 0xa4, 0xa9],
|
||||
},
|
||||
];
|
||||
] as const;
|
||||
|
||||
const messages = [...strings, ...buffers];
|
||||
const messages = [...strings, ...buffers] as const;
|
||||
|
||||
const binaryTypes = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user