mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -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",
|
||||
&["run", "--allow-read", "cli/tests/workers_startup_bench.ts"],
|
||||
&["run", "--allow-read", "cli/tests/workers/bench_startup.ts"],
|
||||
None,
|
||||
),
|
||||
(
|
||||
|
@ -63,7 +63,7 @@ const EXEC_TIME_BENCHMARKS: &[(&str, &[&str], Option<i32>)] = &[
|
|||
&[
|
||||
"run",
|
||||
"--allow-read",
|
||||
"cli/tests/workers_round_robin_bench.ts",
|
||||
"cli/tests/workers/bench_round_robin.ts",
|
||||
],
|
||||
None,
|
||||
),
|
||||
|
|
|
@ -2369,7 +2369,7 @@ console.log("finish");
|
|||
.arg("--allow-net")
|
||||
.arg("--allow-read")
|
||||
.arg("--unstable")
|
||||
.arg("workers_test.ts")
|
||||
.arg("workers/test.ts")
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait()
|
||||
|
@ -2377,6 +2377,18 @@ console.log("finish");
|
|||
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]
|
||||
fn compiler_api() {
|
||||
let status = util::deno_cmd()
|
||||
|
@ -2626,18 +2638,6 @@ console.log("finish");
|
|||
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 {
|
||||
args: "run 075_import_local_query_hash.ts",
|
||||
output: "075_import_local_query_hash.ts.out",
|
||||
|
|
|
@ -5,7 +5,7 @@ unitTest(
|
|||
{ perms: { read: true } },
|
||||
function utimeSyncFileSuccess() {
|
||||
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" },
|
||||
);
|
||||
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 cmdsPerWorker = 400;
|
||||
|
||||
import { Deferred, deferred } from "../../test_util/std/async/deferred.ts";
|
||||
import { Deferred, deferred } from "../../../test_util/std/async/deferred.ts";
|
||||
|
||||
function handleAsyncMsgFromWorker(
|
||||
promiseTable: Map<number, Deferred<string>>,
|
||||
|
@ -22,7 +22,7 @@ async function main(): Promise<void> {
|
|||
const workers: Array<[Map<number, Deferred<string>>, Worker]> = [];
|
||||
for (let i = 1; i <= workerCount; ++i) {
|
||||
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" },
|
||||
);
|
||||
const promise = deferred();
|
|
@ -5,7 +5,7 @@ async function bench(): Promise<void> {
|
|||
const workers: Worker[] = [];
|
||||
for (let i = 1; i <= workerCount; ++i) {
|
||||
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" },
|
||||
);
|
||||
const promise = new Promise<void>((resolve): void => {
|
|
@ -6,9 +6,8 @@ import {
|
|||
assert,
|
||||
assertEquals,
|
||||
assertThrows,
|
||||
fail,
|
||||
} from "../../test_util/std/testing/asserts.ts";
|
||||
import { deferred } from "../../test_util/std/async/deferred.ts";
|
||||
} from "../../../test_util/std/testing/asserts.ts";
|
||||
import { deferred } from "../../../test_util/std/async/deferred.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "worker terminate",
|
||||
|
@ -16,11 +15,11 @@ Deno.test({
|
|||
const promise = deferred();
|
||||
|
||||
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" },
|
||||
);
|
||||
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" },
|
||||
);
|
||||
|
||||
|
@ -73,7 +72,7 @@ Deno.test({
|
|||
const promise = deferred();
|
||||
|
||||
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" },
|
||||
);
|
||||
|
||||
|
@ -93,7 +92,7 @@ Deno.test({
|
|||
fn: async function (): Promise<void> {
|
||||
const promise = deferred();
|
||||
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" },
|
||||
);
|
||||
|
||||
|
@ -115,7 +114,7 @@ Deno.test({
|
|||
const promise = deferred();
|
||||
const workerOptions: WorkerOptions = { type: "module" };
|
||||
const w = new Worker(
|
||||
new URL("workers/worker_globals.ts", import.meta.url).href,
|
||||
new URL("worker_globals.ts", import.meta.url).href,
|
||||
workerOptions,
|
||||
);
|
||||
w.onmessage = (e): void => {
|
||||
|
@ -134,7 +133,7 @@ Deno.test({
|
|||
const promise = deferred();
|
||||
|
||||
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" },
|
||||
);
|
||||
|
||||
|
@ -161,7 +160,7 @@ Deno.test({
|
|||
const promise = deferred();
|
||||
|
||||
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" },
|
||||
);
|
||||
|
||||
|
@ -194,7 +193,7 @@ Deno.test({
|
|||
const promise = deferred();
|
||||
|
||||
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" },
|
||||
);
|
||||
|
||||
|
@ -222,7 +221,7 @@ Deno.test({
|
|||
const promise2 = deferred();
|
||||
|
||||
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" },
|
||||
);
|
||||
|
||||
|
@ -266,7 +265,7 @@ Deno.test({
|
|||
const promise1 = deferred();
|
||||
|
||||
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" },
|
||||
);
|
||||
|
||||
|
@ -295,11 +294,11 @@ Deno.test({
|
|||
const promise2 = deferred();
|
||||
|
||||
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" },
|
||||
);
|
||||
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",
|
||||
deno: {
|
||||
|
@ -333,7 +332,7 @@ Deno.test({
|
|||
fn: async function (): Promise<void> {
|
||||
const promise = deferred();
|
||||
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" },
|
||||
);
|
||||
w.onmessage = (e): void => {
|
||||
|
@ -351,7 +350,7 @@ Deno.test({
|
|||
fn: async function (): Promise<void> {
|
||||
const promise = deferred();
|
||||
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" },
|
||||
);
|
||||
const arr: number[] = [];
|
||||
|
@ -375,7 +374,7 @@ Deno.test({
|
|||
fn: async function (): Promise<void> {
|
||||
const promise = deferred();
|
||||
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" },
|
||||
);
|
||||
setTimeout(() => {
|
||||
|
@ -391,7 +390,7 @@ Deno.test({
|
|||
fn: async function (): Promise<void> {
|
||||
const promise = deferred();
|
||||
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" },
|
||||
);
|
||||
|
||||
|
@ -414,7 +413,7 @@ Deno.test({
|
|||
Deno.test("Worker inherits permissions", async function () {
|
||||
const promise = deferred();
|
||||
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",
|
||||
deno: {
|
||||
|
@ -438,7 +437,7 @@ Deno.test("Worker inherits permissions", async function () {
|
|||
Deno.test("Worker limit children permissions", async function () {
|
||||
const promise = deferred();
|
||||
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",
|
||||
deno: {
|
||||
|
@ -464,14 +463,14 @@ Deno.test("Worker limit children permissions", async function () {
|
|||
Deno.test("Worker limit children permissions granularly", async function () {
|
||||
const promise = deferred();
|
||||
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",
|
||||
deno: {
|
||||
namespace: true,
|
||||
permissions: {
|
||||
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 */
|
||||
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",
|
||||
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 */
|
||||
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,
|
||||
{
|
||||
type: "module",
|
||||
|
@ -545,7 +544,7 @@ Deno.test("Nested worker limit children permissions granularly", async function
|
|||
namespace: true,
|
||||
permissions: {
|
||||
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(
|
||||
() => {
|
||||
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",
|
||||
deno: {
|
||||
|
@ -621,7 +620,7 @@ Deno.test("Worker with disabled permissions", async function () {
|
|||
const promise = deferred();
|
||||
|
||||
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",
|
||||
deno: {
|
||||
|
@ -646,7 +645,7 @@ Deno.test({
|
|||
fn: async function (): Promise<void> {
|
||||
const promise = deferred();
|
||||
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" });
|
||||
w.onmessage = (e): void => {
|
||||
assertEquals(e.data, `${workerModuleHref}, true`);
|
|
@ -1,5 +1,5 @@
|
|||
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" },
|
||||
);
|
||||
setTimeout(() => worker.terminate(), 30000);
|
|
@ -1,5 +1,5 @@
|
|||
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" },
|
||||
);
|
||||
setTimeout(() => worker.terminate(), 30000);
|
Loading…
Reference in a new issue