summaryrefslogtreecommitdiff
path: root/cli/tests/unit/flash_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/flash_test.ts')
-rw-r--r--cli/tests/unit/flash_test.ts62
1 files changed, 38 insertions, 24 deletions
diff --git a/cli/tests/unit/flash_test.ts b/cli/tests/unit/flash_test.ts
index fef45beb9..78340a390 100644
--- a/cli/tests/unit/flash_test.ts
+++ b/cli/tests/unit/flash_test.ts
@@ -1283,29 +1283,35 @@ function createServerLengthTest(name: string, testCase: TestCase) {
await promise;
const decoder = new TextDecoder();
- const buf = new Uint8Array(1024);
- const readResult = await conn.read(buf);
- assert(readResult);
- const msg = decoder.decode(buf.subarray(0, readResult));
-
- try {
- assert(testCase.expects_chunked == hasHeader(msg, "Transfer-Encoding:"));
- assert(testCase.expects_chunked == hasHeader(msg, "chunked"));
- assert(testCase.expects_con_len == hasHeader(msg, "Content-Length:"));
+ let msg = "";
+ while (true) {
+ const buf = new Uint8Array(1024);
+ const readResult = await conn.read(buf);
+ if (!readResult) {
+ break;
+ }
+ msg += decoder.decode(buf.subarray(0, readResult));
+ try {
+ assert(
+ testCase.expects_chunked == hasHeader(msg, "Transfer-Encoding:"),
+ );
+ assert(testCase.expects_chunked == hasHeader(msg, "chunked"));
+ assert(testCase.expects_con_len == hasHeader(msg, "Content-Length:"));
- const n = msg.indexOf("\r\n\r\n") + 4;
+ const n = msg.indexOf("\r\n\r\n") + 4;
- if (testCase.expects_chunked) {
- assertEquals(msg.slice(n + 1, n + 3), "\r\n");
- assertEquals(msg.slice(msg.length - 7), "\r\n0\r\n\r\n");
- }
+ if (testCase.expects_chunked) {
+ assertEquals(msg.slice(n + 1, n + 3), "\r\n");
+ assertEquals(msg.slice(msg.length - 7), "\r\n0\r\n\r\n");
+ }
- if (testCase.expects_con_len && typeof testCase.body === "string") {
- assertEquals(msg.slice(n), testCase.body);
+ if (testCase.expects_con_len && typeof testCase.body === "string") {
+ assertEquals(msg.slice(n), testCase.body);
+ }
+ break;
+ } catch (e) {
+ continue;
}
- } catch (e) {
- console.error(e);
- throw e;
}
conn.close();
@@ -1419,11 +1425,19 @@ Deno.test(
const decoder = new TextDecoder();
{
- const buf = new Uint8Array(1024);
- const readResult = await conn.read(buf);
- assert(readResult);
- const msg = decoder.decode(buf.subarray(0, readResult));
- assert(msg.endsWith("\r\nfoo bar baz\r\n0\r\n\r\n"));
+ let msg = "";
+ while (true) {
+ try {
+ const buf = new Uint8Array(1024);
+ const readResult = await conn.read(buf);
+ assert(readResult);
+ msg += decoder.decode(buf.subarray(0, readResult));
+ assert(msg.endsWith("\r\nfoo bar baz\r\n0\r\n\r\n"));
+ break;
+ } catch {
+ continue;
+ }
+ }
}
// once more!