Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[OV JS] Fix e2e tests (#38133)

Kirill Suvorovc9879810c9ae
diff --git a/.github/workflows/job_openvino_js.yml b/.github/workflows/job_openvino_js.yml
index 3515d8c803a..2cc8a664b45 100644
--- a/.github/workflows/job_openvino_js.yml
+++ b/.github/workflows/job_openvino_js.yml
@@ -82,10 +82,9 @@ jobs:
run: npm run test --loglevel=silly
- name: Install electron deps and run Xvfb
- if: runner.os == 'Linux' && fromJSON(inputs.nodejs-version) >= 22
+ if: runner.os == 'Linux'
run: Xvfb "$DISPLAY" &
- name: E2E of openvino-node package
- if: ${{ 'false' }} # Skipping E2E tests for now due to CVS-192563
working-directory: ${{ env.OPENVINO_JS_DIR }}
run: npm run test:e2e --loglevel=silly
diff --git a/.github/workflows/windows_vs2022_release.yml b/.github/workflows/windows_vs2022_release.yml
index 70941b83d99..27299e40b8c 100644
--- a/.github/workflows/windows_vs2022_release.yml
+++ b/.github/workflows/windows_vs2022_release.yml
@@ -251,12 +251,10 @@ jobs:
uses: microsoft/setup-msbuild@30375c66a4eea26614e0d39710365f22f8b0af57 # v3.0.0
- name: E2E of openvino-node package
- if: ${{ 'false' }} # Skipping E2E tests for now due to CVS-192563
working-directory: ${{ env.OPENVINO_JS_DIR }}
run: npm run test:e2e
- name: E2E of openvino-node package (cmd)
- if: ${{ 'false' }} # Skipping E2E tests for now due to CVS-192563
shell: cmd
working-directory: ${{ env.OPENVINO_JS_DIR }}
run: call npm run test:e2e
diff --git a/src/bindings/js/node/include/infer_request.hpp b/src/bindings/js/node/include/infer_request.hpp
index 341afd90c03..14427842d45 100644
--- a/src/bindings/js/node/include/infer_request.hpp
+++ b/src/bindings/js/node/include/infer_request.hpp
@@ -11,14 +11,16 @@
#include "openvino/runtime/infer_request.hpp"
struct TsfnContext {
- TsfnContext(Napi::Env env) : deferred(Napi::Promise::Deferred::New(env)), _ir(nullptr) {};
+ TsfnContext(Napi::Env env, const ov::InferRequest& infer_request)
+ : deferred(Napi::Promise::Deferred::New(env)),
+ _ir(infer_request) {};
std::thread native_thread;
Napi::Promise::Deferred deferred;
Napi::ThreadSafeFunction tsfn;
- ov::InferRequest* _ir;
+ ov::InferRequest _ir;
ParsedInputData _inputs;
std::map<std::string, ov::Tensor> result;
};
diff --git a/src/bindings/js/node/src/infer_request.cpp b/src/bindings/js/node/src/infer_request.cpp
index dd040b3c8eb..fd61251f1b7 100644
--- a/src/bindings/js/node/src/infer_request.cpp
+++ b/src/bindings/js/node/src/infer_request.cpp
@@ -227,20 +227,20 @@ void perform_inference_thread(TsfnContext* context) {
const std::lock_guard<std::mutex> lock(infer_mutex);
if (const auto* positional_inputs = std::get_if<ov::TensorVector>(&context->_inputs)) {
for (size_t i = 0; i < positional_inputs->size(); ++i) {
- context->_ir->set_input_tensor(i, positional_inputs->at(i));
+ context->_ir.set_input_tensor(i, positional_inputs->at(i));
}
} else {
for (const auto& [name, tensor] : std::get<NamedInputData>(context->_inputs)) {
- context->_ir->set_tensor(name, tensor);
+ context->_ir.set_tensor(name, tensor);
}
}
- context->_ir->infer();
+ context->_ir.infer();
- auto compiled_model = context->_ir->get_compiled_model().outputs();
+ auto compiled_model = context->_ir.get_compiled_model().outputs();
std::map<std::string, ov::Tensor> outputs;
for (auto& node : compiled_model) {
- const auto& tensor = context->_ir->get_tensor(node);
+ const auto& tensor = context->_ir.get_tensor(node);
auto new_tensor = ov::Tensor(tensor.get_element_type(), tensor.get_shape());
tensor.copy_to(new_tensor);
outputs.insert({node.get_any_name(), new_tensor});
@@ -279,8 +279,7 @@ Napi::Value InferRequestWrap::infer_async(const Napi::CallbackInfo& info) {
try {
OPENVINO_ASSERT(info.Length() == 1, "InferAsync method takes as an argument an array or an object.");
- context = new TsfnContext(env);
- context->_ir = &_infer_request;
+ context = new TsfnContext(env, _infer_request);
context->_inputs = parse_input_data(info[0]);
context->tsfn = Napi::ThreadSafeFunction::New(env,
diff --git a/src/bindings/js/node/tests/e2e/demo-electron-app/package.json b/src/bindings/js/node/tests/e2e/demo-electron-app/package.json
index c0662e90cc8..631a05870cd 100644
--- a/src/bindings/js/node/tests/e2e/demo-electron-app/package.json
+++ b/src/bindings/js/node/tests/e2e/demo-electron-app/package.json
@@ -5,7 +5,7 @@
"start": "electron --disable-gpu --no-sandbox ."
},
"devDependencies": {
- "electron": "43.0.0"
+ "electron": "42.11.4"
},
"dependencies": {
"openvino-node": ".."
diff --git a/src/bindings/js/node/tests/e2e/electron-app.test.js b/src/bindings/js/node/tests/e2e/electron-app.test.js
index d217da91111..a8cfbc2056e 100644
--- a/src/bindings/js/node/tests/e2e/electron-app.test.js
+++ b/src/bindings/js/node/tests/e2e/electron-app.test.js
@@ -53,15 +53,15 @@ describe("E2E testing for OpenVINO as an Electron dependency.", function () {
});
});
- after((done) => {
- exec("rm -rf demo-electron-app-project", (error) => {
- if (error) {
- console.error(`exec error: ${error}`);
-
- return done(error);
- }
-
- done();
+ after(async () => {
+ // On Windows, Electron may still hold file handles right after exit and npm
+ // installs some read-only files, so `rm -rf` fails intermittently. fs.rm with
+ // force chmods read-only entries and maxRetries rides out transient locks.
+ await fs.promises.rm("demo-electron-app-project", {
+ recursive: true,
+ force: true,
+ maxRetries: 5,
+ retryDelay: 1000,
});
});
});