mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
chore: Reorganise workers tests (#9493)
This commit is contained in:
parent
1afe6b48e0
commit
8c6d147e6a
14 changed files with 49 additions and 50 deletions
|
@ -55,7 +55,7 @@ const EXEC_TIME_BENCHMARKS: &[(&str, &[&str], Option<i32>)] = &[
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"workers_startup",
|
"workers_startup",
|
||||||
&["run", "--allow-read", "cli/tests/workers_startup_bench.ts"],
|
&["run", "--allow-read", "cli/tests/workers/bench_startup.ts"],
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
@ -63,7 +63,7 @@ const EXEC_TIME_BENCHMARKS: &[(&str, &[&str], Option<i32>)] = &[
|
||||||
&[
|
&[
|
||||||
"run",
|
"run",
|
||||||
"--allow-read",
|
"--allow-read",
|
||||||
"cli/tests/workers_round_robin_bench.ts",
|
"cli/tests/workers/bench_round_robin.ts",
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
|
|
|
@ -2369,7 +2369,7 @@ console.log("finish");
|
||||||
.arg("--allow-net")
|
.arg("--allow-net")
|
||||||
.arg("--allow-read")
|
.arg("--allow-read")
|
||||||
.arg("--unstable")
|
.arg("--unstable")
|
||||||
.arg("workers_test.ts")
|
.arg("workers/test.ts")
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.wait()
|
.wait()
|
||||||
|
@ -2377,6 +2377,18 @@ console.log("finish");
|
||||||
assert!(status.success());
|
assert!(status.success());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itest!(worker_error {
|
||||||
|
args: "run -A workers/worker_error.ts",
|
||||||
|
output: "workers/worker_error.ts.out",
|
||||||
|
exit_code: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
itest!(worker_nested_error {
|
||||||
|
args: "run -A workers/worker_nested_error.ts",
|
||||||
|
output: "workers/worker_nested_error.ts.out",
|
||||||
|
exit_code: 1,
|
||||||
|
});
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compiler_api() {
|
fn compiler_api() {
|
||||||
let status = util::deno_cmd()
|
let status = util::deno_cmd()
|
||||||
|
@ -2626,18 +2638,6 @@ console.log("finish");
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(_073_worker_error {
|
|
||||||
args: "run -A 073_worker_error.ts",
|
|
||||||
output: "073_worker_error.ts.out",
|
|
||||||
exit_code: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
itest!(_074_worker_nested_error {
|
|
||||||
args: "run -A 074_worker_nested_error.ts",
|
|
||||||
output: "074_worker_nested_error.ts.out",
|
|
||||||
exit_code: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
itest!(_075_import_local_query_hash {
|
itest!(_075_import_local_query_hash {
|
||||||
args: "run 075_import_local_query_hash.ts",
|
args: "run 075_import_local_query_hash.ts",
|
||||||
output: "075_import_local_query_hash.ts.out",
|
output: "075_import_local_query_hash.ts.out",
|
||||||
|
|
|
@ -5,7 +5,7 @@ unitTest(
|
||||||
{ perms: { read: true } },
|
{ perms: { read: true } },
|
||||||
function utimeSyncFileSuccess() {
|
function utimeSyncFileSuccess() {
|
||||||
const w = new Worker(
|
const w = new Worker(
|
||||||
new URL("../subdir/worker_types.ts", import.meta.url).href,
|
new URL("../workers/worker_types.ts", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
assert(w);
|
assert(w);
|
||||||
|
|
|
@ -5,7 +5,7 @@ const data = "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n";
|
||||||
const workerCount = 4;
|
const workerCount = 4;
|
||||||
const cmdsPerWorker = 400;
|
const cmdsPerWorker = 400;
|
||||||
|
|
||||||
import { Deferred, deferred } from "../../test_util/std/async/deferred.ts";
|
import { Deferred, deferred } from "../../../test_util/std/async/deferred.ts";
|
||||||
|
|
||||||
function handleAsyncMsgFromWorker(
|
function handleAsyncMsgFromWorker(
|
||||||
promiseTable: Map<number, Deferred<string>>,
|
promiseTable: Map<number, Deferred<string>>,
|
||||||
|
@ -22,7 +22,7 @@ async function main(): Promise<void> {
|
||||||
const workers: Array<[Map<number, Deferred<string>>, Worker]> = [];
|
const workers: Array<[Map<number, Deferred<string>>, Worker]> = [];
|
||||||
for (let i = 1; i <= workerCount; ++i) {
|
for (let i = 1; i <= workerCount; ++i) {
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("workers/bench_worker.ts", import.meta.url).href,
|
new URL("bench_worker.ts", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
const promise = deferred();
|
const promise = deferred();
|
|
@ -5,7 +5,7 @@ async function bench(): Promise<void> {
|
||||||
const workers: Worker[] = [];
|
const workers: Worker[] = [];
|
||||||
for (let i = 1; i <= workerCount; ++i) {
|
for (let i = 1; i <= workerCount; ++i) {
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("workers/bench_worker.ts", import.meta.url).href,
|
new URL("bench_worker.ts", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
const promise = new Promise<void>((resolve): void => {
|
const promise = new Promise<void>((resolve): void => {
|
|
@ -6,9 +6,8 @@ import {
|
||||||
assert,
|
assert,
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertThrows,
|
assertThrows,
|
||||||
fail,
|
} from "../../../test_util/std/testing/asserts.ts";
|
||||||
} from "../../test_util/std/testing/asserts.ts";
|
import { deferred } from "../../../test_util/std/async/deferred.ts";
|
||||||
import { deferred } from "../../test_util/std/async/deferred.ts";
|
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "worker terminate",
|
name: "worker terminate",
|
||||||
|
@ -16,11 +15,11 @@ Deno.test({
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
|
|
||||||
const jsWorker = new Worker(
|
const jsWorker = new Worker(
|
||||||
new URL("workers/test_worker.js", import.meta.url).href,
|
new URL("test_worker.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
const tsWorker = new Worker(
|
const tsWorker = new Worker(
|
||||||
new URL("workers/test_worker.ts", import.meta.url).href,
|
new URL("test_worker.ts", import.meta.url).href,
|
||||||
{ type: "module", name: "tsWorker" },
|
{ type: "module", name: "tsWorker" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ Deno.test({
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
|
|
||||||
const nestedWorker = new Worker(
|
const nestedWorker = new Worker(
|
||||||
new URL("workers/nested_worker.js", import.meta.url).href,
|
new URL("nested_worker.js", import.meta.url).href,
|
||||||
{ type: "module", name: "nested" },
|
{ type: "module", name: "nested" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -93,7 +92,7 @@ Deno.test({
|
||||||
fn: async function (): Promise<void> {
|
fn: async function (): Promise<void> {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const throwingWorker = new Worker(
|
const throwingWorker = new Worker(
|
||||||
new URL("workers/throwing_worker.js", import.meta.url).href,
|
new URL("throwing_worker.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -115,7 +114,7 @@ Deno.test({
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const workerOptions: WorkerOptions = { type: "module" };
|
const workerOptions: WorkerOptions = { type: "module" };
|
||||||
const w = new Worker(
|
const w = new Worker(
|
||||||
new URL("workers/worker_globals.ts", import.meta.url).href,
|
new URL("worker_globals.ts", import.meta.url).href,
|
||||||
workerOptions,
|
workerOptions,
|
||||||
);
|
);
|
||||||
w.onmessage = (e): void => {
|
w.onmessage = (e): void => {
|
||||||
|
@ -134,7 +133,7 @@ Deno.test({
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
|
|
||||||
const fetchingWorker = new Worker(
|
const fetchingWorker = new Worker(
|
||||||
new URL("workers/fetching_worker.js", import.meta.url).href,
|
new URL("fetching_worker.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -161,7 +160,7 @@ Deno.test({
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
|
|
||||||
const busyWorker = new Worker(
|
const busyWorker = new Worker(
|
||||||
new URL("workers/busy_worker.js", import.meta.url).href,
|
new URL("busy_worker.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -194,7 +193,7 @@ Deno.test({
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
|
|
||||||
const racyWorker = new Worker(
|
const racyWorker = new Worker(
|
||||||
new URL("workers/racy_worker.js", import.meta.url).href,
|
new URL("racy_worker.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -222,7 +221,7 @@ Deno.test({
|
||||||
const promise2 = deferred();
|
const promise2 = deferred();
|
||||||
|
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("workers/event_worker.js", import.meta.url).href,
|
new URL("event_worker.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -266,7 +265,7 @@ Deno.test({
|
||||||
const promise1 = deferred();
|
const promise1 = deferred();
|
||||||
|
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("workers/event_worker_scope.js", import.meta.url).href,
|
new URL("event_worker_scope.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -295,11 +294,11 @@ Deno.test({
|
||||||
const promise2 = deferred();
|
const promise2 = deferred();
|
||||||
|
|
||||||
const regularWorker = new Worker(
|
const regularWorker = new Worker(
|
||||||
new URL("workers/non_deno_worker.js", import.meta.url).href,
|
new URL("non_deno_worker.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
const denoWorker = new Worker(
|
const denoWorker = new Worker(
|
||||||
new URL("workers/deno_worker.ts", import.meta.url).href,
|
new URL("deno_worker.ts", import.meta.url).href,
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
deno: {
|
deno: {
|
||||||
|
@ -333,7 +332,7 @@ Deno.test({
|
||||||
fn: async function (): Promise<void> {
|
fn: async function (): Promise<void> {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const w = new Worker(
|
const w = new Worker(
|
||||||
new URL("workers/worker_crypto.js", import.meta.url).href,
|
new URL("worker_crypto.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
w.onmessage = (e): void => {
|
w.onmessage = (e): void => {
|
||||||
|
@ -351,7 +350,7 @@ Deno.test({
|
||||||
fn: async function (): Promise<void> {
|
fn: async function (): Promise<void> {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const w = new Worker(
|
const w = new Worker(
|
||||||
new URL("workers/test_worker.ts", import.meta.url).href,
|
new URL("test_worker.ts", import.meta.url).href,
|
||||||
{ type: "module", name: "tsWorker" },
|
{ type: "module", name: "tsWorker" },
|
||||||
);
|
);
|
||||||
const arr: number[] = [];
|
const arr: number[] = [];
|
||||||
|
@ -375,7 +374,7 @@ Deno.test({
|
||||||
fn: async function (): Promise<void> {
|
fn: async function (): Promise<void> {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const w = new Worker(
|
const w = new Worker(
|
||||||
new URL("./workers/immediately_close_worker.js", import.meta.url).href,
|
new URL("./immediately_close_worker.js", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -391,7 +390,7 @@ Deno.test({
|
||||||
fn: async function (): Promise<void> {
|
fn: async function (): Promise<void> {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("./worker_post_undefined.ts", import.meta.url).href,
|
new URL("./post_undefined.ts", import.meta.url).href,
|
||||||
{ type: "module" },
|
{ type: "module" },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -414,7 +413,7 @@ Deno.test({
|
||||||
Deno.test("Worker inherits permissions", async function () {
|
Deno.test("Worker inherits permissions", async function () {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("./workers/read_check_worker.js", import.meta.url).href,
|
new URL("./read_check_worker.js", import.meta.url).href,
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
deno: {
|
deno: {
|
||||||
|
@ -438,7 +437,7 @@ Deno.test("Worker inherits permissions", async function () {
|
||||||
Deno.test("Worker limit children permissions", async function () {
|
Deno.test("Worker limit children permissions", async function () {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("./workers/read_check_worker.js", import.meta.url).href,
|
new URL("./read_check_worker.js", import.meta.url).href,
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
deno: {
|
deno: {
|
||||||
|
@ -464,14 +463,14 @@ Deno.test("Worker limit children permissions", async function () {
|
||||||
Deno.test("Worker limit children permissions granularly", async function () {
|
Deno.test("Worker limit children permissions granularly", async function () {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("./workers/read_check_granular_worker.js", import.meta.url).href,
|
new URL("./read_check_granular_worker.js", import.meta.url).href,
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
deno: {
|
deno: {
|
||||||
namespace: true,
|
namespace: true,
|
||||||
permissions: {
|
permissions: {
|
||||||
read: [
|
read: [
|
||||||
new URL("./workers/read_check_worker.js", import.meta.url),
|
new URL("./read_check_worker.js", import.meta.url),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -510,7 +509,7 @@ Deno.test("Nested worker limit children permissions", async function () {
|
||||||
|
|
||||||
/** This worker has read permissions but doesn't grant them to its children */
|
/** This worker has read permissions but doesn't grant them to its children */
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("./workers/parent_read_check_worker.js", import.meta.url).href,
|
new URL("./parent_read_check_worker.js", import.meta.url).href,
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
deno: {
|
deno: {
|
||||||
|
@ -537,7 +536,7 @@ Deno.test("Nested worker limit children permissions granularly", async function
|
||||||
|
|
||||||
/** This worker has read permissions but doesn't grant them to its children */
|
/** This worker has read permissions but doesn't grant them to its children */
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("./workers/parent_read_check_granular_worker.js", import.meta.url)
|
new URL("./parent_read_check_granular_worker.js", import.meta.url)
|
||||||
.href,
|
.href,
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
|
@ -545,7 +544,7 @@ Deno.test("Nested worker limit children permissions granularly", async function
|
||||||
namespace: true,
|
namespace: true,
|
||||||
permissions: {
|
permissions: {
|
||||||
read: [
|
read: [
|
||||||
new URL("./workers/read_check_granular_worker.js", import.meta.url),
|
new URL("./read_check_granular_worker.js", import.meta.url),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -599,7 +598,7 @@ Deno.test("Worker initialization throws on worker permissions greater than paren
|
||||||
assertThrows(
|
assertThrows(
|
||||||
() => {
|
() => {
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("./workers/deno_worker.ts", import.meta.url).href,
|
new URL("./deno_worker.ts", import.meta.url).href,
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
deno: {
|
deno: {
|
||||||
|
@ -621,7 +620,7 @@ Deno.test("Worker with disabled permissions", async function () {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
|
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("./workers/no_permissions_worker.js", import.meta.url).href,
|
new URL("./no_permissions_worker.js", import.meta.url).href,
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
deno: {
|
deno: {
|
||||||
|
@ -646,7 +645,7 @@ Deno.test({
|
||||||
fn: async function (): Promise<void> {
|
fn: async function (): Promise<void> {
|
||||||
const promise = deferred();
|
const promise = deferred();
|
||||||
const workerModuleHref =
|
const workerModuleHref =
|
||||||
new URL("subdir/worker_location.ts", import.meta.url).href;
|
new URL("worker_location.ts", import.meta.url).href;
|
||||||
const w = new Worker(workerModuleHref, { type: "module" });
|
const w = new Worker(workerModuleHref, { type: "module" });
|
||||||
w.onmessage = (e): void => {
|
w.onmessage = (e): void => {
|
||||||
assertEquals(e.data, `${workerModuleHref}, true`);
|
assertEquals(e.data, `${workerModuleHref}, true`);
|
|
@ -1,5 +1,5 @@
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("subdir/worker_error.ts", import.meta.url).href,
|
new URL("error.ts", import.meta.url).href,
|
||||||
{ type: "module", name: "bar" },
|
{ type: "module", name: "bar" },
|
||||||
);
|
);
|
||||||
setTimeout(() => worker.terminate(), 30000);
|
setTimeout(() => worker.terminate(), 30000);
|
|
@ -1,5 +1,5 @@
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("073_worker_error.ts", import.meta.url).href,
|
new URL("worker_error.ts", import.meta.url).href,
|
||||||
{ type: "module", name: "baz" },
|
{ type: "module", name: "baz" },
|
||||||
);
|
);
|
||||||
setTimeout(() => worker.terminate(), 30000);
|
setTimeout(() => worker.terminate(), 30000);
|
Loading…
Reference in a new issue