Skip to content

Commit eb67185

Browse files
Guy BedfordJakeChampion
authored andcommitted
use response test
1 parent b6efba7 commit eb67185

File tree

2 files changed

+95
-94
lines changed

2 files changed

+95
-94
lines changed

integration-tests/js-compute/fixtures/byob/bin/index.js

Lines changed: 93 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -14,107 +14,112 @@ addEventListener("fetch", async (event) => {
1414
type: 'bytes',
1515
autoAllocateChunkSize: 1024,
1616
async pull (controller) {
17+
const view = controller.byobRequest.view;
18+
1719
if (cnt === 0) {
18-
{
19-
let cnt = 0;
20-
const stream = new ReadableStream({
21-
type: 'bytes',
22-
autoAllocateChunkSize: 1024,
23-
start (controller) {
24-
},
25-
pull (controller) {
26-
cnt++;
27-
const view = controller.byobRequest?.view;
28-
if (cnt < 3) {
29-
view[0] = 1;
30-
view[1] = 2;
31-
view[2] = 3;
32-
controller.byobRequest.respond(3);
33-
} else if (cnt == 3) {
34-
controller.enqueue(new Uint8Array([1,2,4]));
35-
}
36-
if (cnt === 3)
37-
return controller.close();
20+
let cnt = 0;
21+
const stream = new ReadableStream({
22+
type: 'bytes',
23+
autoAllocateChunkSize: 1024,
24+
start (controller) {
25+
},
26+
pull (controller) {
27+
cnt++;
28+
const view = controller.byobRequest?.view;
29+
if (cnt < 3) {
30+
view[0] = 1;
31+
view[1] = 2;
32+
view[2] = 3;
33+
controller.byobRequest.respond(3);
34+
} else if (cnt == 3) {
35+
controller.enqueue(new Uint8Array([1,2,4]));
3836
}
39-
});
40-
41-
const byobReader = stream.getReader();
42-
let buf;
43-
let result;
44-
let offset = 0;
45-
while (true) {
46-
if (buf && cnt < 3) {
47-
const output = new Uint8Array(buf);
48-
strictEqual(output[0], 1);
49-
strictEqual(output[1], 2);
50-
strictEqual(output[2], 3);
51-
strictEqual(output[3], 0);
52-
strictEqual(output.byteLength, 1024);
53-
}
54-
result = await byobReader.read();
55-
if (result.done)
56-
break;
57-
offset += result.value.byteLength;
58-
buf = result.value.buffer;
37+
if (cnt === 3)
38+
return controller.close();
5939
}
40+
});
6041

61-
strictEqual(cnt, 3);
62-
const output = new Uint8Array(buf);
63-
strictEqual(output[0], 1);
64-
strictEqual(output[1], 2);
65-
strictEqual(output[2], 4);
66-
strictEqual(output[3], undefined);
67-
strictEqual(output.byteLength, 3);
68-
console.log('Passed 1');
42+
const byobReader = stream.getReader();
43+
let buf;
44+
let result;
45+
let offset = 0;
46+
while (true) {
47+
if (buf && cnt < 3) {
48+
const output = new Uint8Array(buf);
49+
strictEqual(output[0], 1);
50+
strictEqual(output[1], 2);
51+
strictEqual(output[2], 3);
52+
strictEqual(output[3], 0);
53+
strictEqual(output.byteLength, 1024);
54+
}
55+
result = await byobReader.read();
56+
if (result.done)
57+
break;
58+
offset += result.value.byteLength;
59+
buf = result.value.buffer;
6960
}
70-
71-
{
72-
let cnt = 0;
73-
const stream = new ReadableStream({
74-
type: 'bytes',
75-
start (controller) {
76-
},
77-
pull (controller) {
78-
cnt++;
79-
const view = controller.byobRequest?.view;
80-
if (view) {
81-
view[0] = 1;
82-
view[1] = 2;
83-
view[2] = 3;
84-
controller.byobRequest.respond(3);
85-
}
86-
if (cnt === 3)
87-
return controller.close();
61+
62+
strictEqual(cnt, 3);
63+
const output = new Uint8Array(buf);
64+
strictEqual(output[0], 1);
65+
strictEqual(output[1], 2);
66+
strictEqual(output[2], 4);
67+
strictEqual(output[3], undefined);
68+
strictEqual(output.byteLength, 3);
69+
view[0] = 104;
70+
view[1] = 101;
71+
view[2] = 121;
72+
view[3] = 49;
73+
controller.byobRequest.respond(4);
74+
}
75+
else if (cnt === 1) {
76+
let cnt = 0;
77+
const stream = new ReadableStream({
78+
type: 'bytes',
79+
start (controller) {
80+
},
81+
pull (controller) {
82+
cnt++;
83+
const view = controller.byobRequest?.view;
84+
if (view) {
85+
view[0] = 1;
86+
view[1] = 2;
87+
view[2] = 3;
88+
controller.byobRequest.respond(3);
8889
}
89-
});
90-
91-
const byobReader = stream.getReader({ mode: 'byob' });
92-
let buf = new ArrayBuffer(10);
93-
let result;
94-
let offset = 0;
95-
do {
96-
result = await byobReader.read(new Uint8Array(buf, offset));
97-
offset += result.value.byteLength;
98-
buf = result.value.buffer;
99-
} while(!result.done);
100-
101-
const out = new Uint8Array(buf);
102-
if (out[0] === 1 && out[1] === 2 && out[2] === 3 && out[3] === 1 && out[4] === 2 && out[5] === 3 && out[6] === 1 && out[7] === 2 && out[8] === 3) {
103-
console.log('Passed 2');
90+
if (cnt === 3)
91+
return controller.close();
10492
}
93+
});
94+
95+
const byobReader = stream.getReader({ mode: 'byob' });
96+
let buf = new ArrayBuffer(10);
97+
let result;
98+
let offset = 0;
99+
do {
100+
result = await byobReader.read(new Uint8Array(buf, offset));
101+
offset += result.value.byteLength;
102+
buf = result.value.buffer;
103+
} while(!result.done);
104+
105+
const out = new Uint8Array(buf);
106+
if (out[0] === 1 && out[1] === 2 && out[2] === 3 && out[3] === 1 && out[4] === 2 && out[5] === 3 && out[6] === 1 && out[7] === 2 && out[8] === 3) {
107+
view[0] = 104;
108+
view[1] = 101;
109+
view[2] = 121;
110+
view[3] = 50;
111+
controller.byobRequest.respond(4);
105112
}
106113
}
107-
108-
cnt++;
109-
const view = controller.byobRequest.view;
110-
if (view) {
114+
else if (cnt === 2) {
111115
view[0] = 104;
112116
view[1] = 101;
113117
view[2] = 121;
114-
controller.byobRequest.respond(3);
118+
view[3] = 51;
119+
controller.byobRequest.respond(4);
120+
controller.close();
115121
}
116-
if (cnt === 3)
117-
return controller.close();
122+
cnt++;
118123
}
119124
});
120125
event.respondWith(new Response(stream));

integration-tests/js-compute/fixtures/byob/tests.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
},
88
"downstream_response": {
99
"status": 200,
10-
"body": "heyheyhey"
11-
},
12-
"logs": [
13-
"stdout :: Log: Passed 1",
14-
"stdout :: Log: Passed 2"
15-
]
10+
"body": "hey1hey2hey3"
11+
}
1612
}
1713
}

0 commit comments

Comments
 (0)