forked from langchain-ai/langchainjs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix random test fails due to segfault by chromadb & Float32Array not …
…shared in jest context isolation The way chromadb imports @xenova/transformers package in file chromadb/src/embeddings/TransformersEmbeddingFunction.ts:33 makes it result in random segment fault errors terminating the tests prematurely. This fix contains a code that bypasses chromadb package and directly uses the @xenova/transformers package Due to how jest isolates the context of each running test (xenova/transformers.js#57, https://github.com/kayahr/jest-environment-node-single-context, jestjs/jest#2549) - it makes it impossible for onnxruntime-node package to validate the array passed as an input to it is actually an `instanceof Float32Array` type. The `instanceof` results in false because the globals are different between context. This commit shares the Float32Array global between each context.
- Loading branch information
Juraj Carnogursky
committed
Sep 3, 2023
1 parent
d3c1247
commit 827a076
Showing
5 changed files
with
85 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Jest single run all tests", | ||
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js", | ||
"env": { "CI": "true" }, | ||
"args": [ | ||
"-c", | ||
"./langchain/jest.config.cjs", | ||
"--verbose", | ||
"-i", | ||
"--no-cache" | ||
], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Jest watch all tests", | ||
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js", | ||
"args": [ | ||
"-c", | ||
"./langchain/jest.config.cjs", | ||
"--verbose", | ||
"-i", | ||
"--no-cache", | ||
"--watchAll" | ||
], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Jest watch current file", | ||
"program": "${workspaceFolder}/node_modules/jest/bin/jest", | ||
"env": { | ||
"NODE_OPTIONS": "--experimental-vm-modules" | ||
}, | ||
"args": [ | ||
"${fileBasename}", | ||
"-c", | ||
"./langchain/jest.config.cjs", | ||
"--verbose", | ||
"-i", | ||
"--no-cache", | ||
"--watchAll" | ||
], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { TestEnvironment } = require("jest-environment-node"); | ||
|
||
class AdjustedTestEnvironmentToSupportFloat32Array extends TestEnvironment { | ||
constructor(config, context) { | ||
// Make `instanceof Float32Array return true in tests | ||
super(config, context); | ||
this.global.Float32Array = Float32Array; | ||
} | ||
} | ||
|
||
module.exports = AdjustedTestEnvironmentToSupportFloat32Array; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters