Skip to content

Commit

Permalink
fix(nitro-node/test): logic for extracting JSON from chunk data
Browse files Browse the repository at this point in the history
  • Loading branch information
InNoobWeTrust committed Feb 21, 2024
1 parent d43f50d commit 7190ab2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-nitro-node.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build nitro-node

on:
#schedule:
# - cron: "0 20 * * *" # At 8 PM UTC, which is 3 AM UTC+7
schedule:
- cron: "0 20 * * *" # At 0:20 UTC, which is 7:20 AM UTC+7
push:
branches:
- main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
schedule:
- cron: "0 20 * * *" # At 8 PM UTC, which is 3 AM UTC+7
- cron: "0 20 * * *" # At 0:20 UTC, which is 7:20 AM UTC+7
push:
branches:
- main
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-install-nitro-node.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Test install nitro-node

on:
#schedule:
# - cron: "0 20 * * *" # At 8 PM UTC, which is 3 AM UTC+7
schedule:
- cron: "0 20 * * *" # At 0:20 UTC, which is 7:20 AM UTC+7
push:
branches:
- main
Expand Down
14 changes: 11 additions & 3 deletions nitro-node/test/nitro-process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ describe("Manage nitro process", () => {
await validateModelStatus();
// Arrays of all the chunked response
let streamedContent: Record<string, any>[] = [];
let chunkCounter = 0;
// Run chat completion with stream
const response = await chatCompletion(
{
Expand Down Expand Up @@ -208,7 +209,14 @@ describe("Manage nitro process", () => {
if (data.match(/\[DONE\]/)) {
return;
}
streamedContent.push(JSON.parse(data));
chunkCounter++;
try {
// Parse the streamed content
streamedContent.push(JSON.parse(data));
} catch (e) {
// Skip invalid json data
console.error(e, data);
}
},
//close() {},
//abort(_err) {}
Expand All @@ -227,8 +235,8 @@ describe("Manage nitro process", () => {
await expect(response.json).rejects.toThrow();
// Response body should be used already
expect(response.bodyUsed).toBeTruthy();
// There should be multiple chunks of json data
expect(streamedContent.length).toBeGreaterThan(0);
// There should be no invalid chunk of json data
expect(streamedContent.length).toEqual(chunkCounter);
// Stop nitro
await stopModel();
},
Expand Down

0 comments on commit 7190ab2

Please sign in to comment.