mirror of
https://github.com/denoland/deno.git
synced 2024-11-27 16:10:57 -05:00
6e2df8c64f
This PR brings assertOps and assertResources sanitizers to Deno.test() API. assertOps checks that test doesn't leak async ops, ie. there are no unresolved promises originating from Deno APIs. Enabled by default, can be disabled using Deno.TestDefinition.disableOpSanitizer. assertResources checks that test doesn't leak resources, ie. all resources used in test are closed. For example; if a file is opened during a test case it must be explicitly closed before test case finishes. It's most useful for asynchronous generators. Enabled by default, can be disabled using Deno.TestDefinition.disableResourceSanitizer. We've used those sanitizers in internal runtime tests and it proved very useful in surfacing incorrect tests which resulted in interference between the tests. All tests have been sanitized. Closes #4208
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
const { test } = Deno;
|
|
import { bench, runBenchmarks } from "./bench.ts";
|
|
|
|
import "./bench_example.ts";
|
|
|
|
test({
|
|
name: "benching",
|
|
|
|
fn: async function(): Promise<void> {
|
|
bench(function forIncrementX1e9(b): void {
|
|
b.start();
|
|
for (let i = 0; i < 1e9; i++);
|
|
b.stop();
|
|
});
|
|
|
|
bench(function forDecrementX1e9(b): void {
|
|
b.start();
|
|
for (let i = 1e9; i > 0; i--);
|
|
b.stop();
|
|
});
|
|
|
|
bench(async function forAwaitFetchDenolandX10(b): Promise<void> {
|
|
b.start();
|
|
for (let i = 0; i < 10; i++) {
|
|
const r = await fetch("https://deno.land/");
|
|
await r.text();
|
|
}
|
|
b.stop();
|
|
});
|
|
|
|
bench(async function promiseAllFetchDenolandX10(b): Promise<void> {
|
|
const urls = new Array(10).fill("https://deno.land/");
|
|
b.start();
|
|
await Promise.all(
|
|
urls.map(
|
|
async (denoland: string): Promise<void> => {
|
|
const r = await fetch(denoland);
|
|
await r.text();
|
|
}
|
|
)
|
|
);
|
|
b.stop();
|
|
});
|
|
|
|
bench({
|
|
name: "runs100ForIncrementX1e6",
|
|
runs: 100,
|
|
func(b): void {
|
|
b.start();
|
|
for (let i = 0; i < 1e6; i++);
|
|
b.stop();
|
|
}
|
|
});
|
|
|
|
bench(function throwing(b): void {
|
|
b.start();
|
|
// Throws bc the timer's stop method is never called
|
|
});
|
|
|
|
await runBenchmarks({ skip: /throw/ });
|
|
}
|
|
});
|