diff --git a/lint.ignore b/lint.ignore index 672a5412a3fd4f..6d12f2b94bc98d 100644 --- a/lint.ignore +++ b/lint.ignore @@ -311,6 +311,7 @@ SET TIMEOUT: webaudio/the-audio-api/the-mediaelementaudiosourcenode-interface/me SET TIMEOUT: webauthn/*timeout.https.html SET TIMEOUT: webdriver/* SET TIMEOUT: webmessaging/* +SET TIMEOUT: webnn/resources/utils.js SET TIMEOUT: webrtc-encoded-transform/script-metadata-transform-worker.js SET TIMEOUT: webrtc-encoded-transform/script-transform-generateKeyFrame.js SET TIMEOUT: webrtc-encoded-transform/script-transform-sendKeyFrameRequest.js diff --git a/webnn/resources/utils.js b/webnn/resources/utils.js index 82941300705d29..56e95147567745 100644 --- a/webnn/resources/utils.js +++ b/webnn/resources/utils.js @@ -208,8 +208,21 @@ async function getContext() { try { context = await navigator.ml.createContext(contextOptions); } catch (e) { - throw new AssertionError( - `Unable to create context for ${variant} variant. ${e}`); + // A previous test case may kill the GPU process on which the WebNN service + // runs. If you call `createContext` again immediately before the GPU + // process restarts, it will fail again. So wait a moment and retry. + if (e.message.includes('WebNN service connection error.')) { + await new Promise(resolve => setTimeout(resolve, 3000)); + try { + context = await navigator.ml.createContext(contextOptions); + } catch (retryError) { + throw new AssertionError( + `Unable to create context for ${variant} variant on retry. ${retryError}`); + } + } else { + throw new AssertionError( + `Unable to create context for ${variant} variant. ${e}`); + } } return context; }