11cb0ef41Sopenharmony_ci// Flags: --no-node-snapshot
21cb0ef41Sopenharmony_ci// With node snapshot the OOM can occur during the deserialization of the
31cb0ef41Sopenharmony_ci// context, so disable it since we want the OOM to occur during the creation of
41cb0ef41Sopenharmony_ci// the message port.
51cb0ef41Sopenharmony_ci'use strict';
61cb0ef41Sopenharmony_ciconst common = require('../common');
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// Do not use isMainThread so that this test itself can be run inside a Worker.
111cb0ef41Sopenharmony_ciif (!process.env.HAS_STARTED_WORKER) {
121cb0ef41Sopenharmony_ci  process.env.HAS_STARTED_WORKER = 1;
131cb0ef41Sopenharmony_ci  const opts = {
141cb0ef41Sopenharmony_ci    resourceLimits: {
151cb0ef41Sopenharmony_ci      maxYoungGenerationSizeMb: 0,
161cb0ef41Sopenharmony_ci      maxOldGenerationSizeMb: 0
171cb0ef41Sopenharmony_ci    },
181cb0ef41Sopenharmony_ci  };
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  const worker = new Worker(__filename, opts);
211cb0ef41Sopenharmony_ci  worker.on('error', common.mustCall((err) => {
221cb0ef41Sopenharmony_ci    assert.strictEqual(err.code, 'ERR_WORKER_OUT_OF_MEMORY');
231cb0ef41Sopenharmony_ci  }));
241cb0ef41Sopenharmony_ci} else {
251cb0ef41Sopenharmony_ci  setInterval(() => {}, 1);
261cb0ef41Sopenharmony_ci}
27