Skip to content

Commit 1c21c9a

Browse files
author
Guy Bedford
authored
Complete StarlingMonkey SDK Tests (#807)
1 parent 514d014 commit 1c21c9a

File tree

10 files changed

+112
-24
lines changed

10 files changed

+112
-24
lines changed

.github/workflows/starlingmonkey.yml

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,88 @@ jobs:
2727
rustup toolchain install 1.77.1
2828
rustup target add wasm32-wasi --toolchain 1.77.1
2929
- name: Build
30-
run: npm run build:starlingmonkey:debug
30+
run: npm run build:starlingmonkey
3131
- uses: actions/upload-artifact@v3
3232
with:
33-
name: starling-debug
33+
name: starling-release
3434
path: starling.wasm
3535

36+
ensure_cargo_installs:
37+
name: Ensure that all required "cargo install" commands are run, or we have a cache hit
38+
strategy:
39+
matrix:
40+
include:
41+
- crate: viceroy
42+
version: 0.9.4 # Note: workflow-level env vars can't be used in matrix definitions
43+
options: ""
44+
- crate: wasm-tools
45+
version: 1.0.28 # Note: workflow-level env vars can't be used in matrix definitions
46+
options: ""
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Cache ${{ matrix.crate }} ${{ matrix.version }}
50+
id: cache-crate
51+
uses: actions/cache@v3
52+
with:
53+
path: "/home/runner/.cargo/bin/${{ matrix.crate }}"
54+
key: crate-cache-${{ matrix.crate }}-${{ matrix.version }}
55+
- name: Install ${{ matrix.crate }} ${{ matrix.version }}
56+
run: cargo install ${{ matrix.crate }} ${{ matrix.options }} --version ${{ matrix.version }}
57+
if: steps.cache-crate.outputs.cache-hit != 'true'
58+
59+
run_wpt:
60+
if: github.ref != 'refs/heads/main' && false
61+
name: Run Web Platform Tests
62+
needs: [build, ensure_cargo_installs]
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v3
66+
with:
67+
submodules: true
68+
- uses: actions/setup-node@v3
69+
with:
70+
node-version: 20
71+
cache: 'yarn'
72+
73+
- name: Download Engine
74+
uses: actions/download-artifact@v3
75+
with:
76+
name: starling-release
77+
78+
- name: Restore Viceroy from cache
79+
uses: actions/cache@v3
80+
with:
81+
path: "/home/runner/.cargo/bin/viceroy"
82+
key: crate-cache-viceroy-${{ env.viceroy_version }}
83+
84+
- name: Restore wasm-tools from cache
85+
uses: actions/cache@v3
86+
id: wasm-tools
87+
with:
88+
path: "/home/runner/.cargo/bin/wasm-tools"
89+
key: crate-cache-wasm-tools-${{ env.wasm-tools_version }}
90+
91+
- name: "Check wasm-tools has been restored"
92+
if: steps.wasm-tools.outputs.cache-hit != 'true'
93+
run: |
94+
echo "wasm-tools was not restored from the cache"
95+
echo "bailing out from the build early"
96+
exit 1
97+
98+
- run: yarn install --frozen-lockfile
99+
100+
- name: Build WPT runtime
101+
run: tests/wpt-harness/build-wpt-runtime.sh --starlingmonkey
102+
103+
- name: Prepare WPT hosts
104+
run: |
105+
cd tests/wpt-harness/wpt
106+
./wpt make-hosts-file | sudo tee -a /etc/hosts
107+
108+
- name: Run tests
109+
timeout-minutes: 20
110+
run: node ./tests/wpt-harness/run-wpt.mjs --starlingmonkey -vv
111+
36112
sdktest:
37113
if: github.ref != 'refs/heads/main'
38114
runs-on: ubuntu-latest
@@ -76,7 +152,7 @@ jobs:
76152
- name: Download Engine
77153
uses: actions/download-artifact@v3
78154
with:
79-
name: starling-debug
155+
name: starling-release
80156
- run: yarn install --frozen-lockfile
81157

82158
- name: Yarn install

integration-tests/js-compute/fixtures/app/tests-skip-starlingmonkey.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

integration-tests/js-compute/test.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ let args = argv.slice(2);
3737

3838
const local = args.includes('--local');
3939
const starlingmonkey = args.includes('--starlingmonkey');
40+
const filter = args.filter(arg => !arg.startsWith('--'));
4041

4142
async function $(...args) {
4243
return await retry(10, () => zx(...args))
@@ -111,11 +112,6 @@ core.endGroup()
111112

112113
let { default: tests } = await import(join(fixturePath, 'tests.json'), { with: { type: 'json' } });
113114

114-
if (starlingmonkey) {
115-
const { default: testsSkipStarlingMonkey } = await import(join(fixturePath, 'tests-skip-starlingmonkey.json'), { with: { type: 'json' } });
116-
tests = Object.fromEntries(Object.entries(tests).filter(([key]) => !testsSkipStarlingMonkey.includes(key)));
117-
}
118-
119115
core.startGroup('Running tests')
120116
function chunks(arr, size) {
121117
const output = [];
@@ -128,6 +124,14 @@ function chunks(arr, size) {
128124
let results = [];
129125
for (const chunk of chunks(Object.entries(tests), 100)) {
130126
results.push(...await Promise.allSettled(chunk.map(async ([title, test]) => {
127+
// basic test filtering
128+
if (!title.includes(filter)) {
129+
return {
130+
title,
131+
test,
132+
skipped: true
133+
};
134+
}
131135
if (local) {
132136
if (test.environments.includes("viceroy")) {
133137
let path = test.downstream_request.pathname;
@@ -142,6 +146,7 @@ for (const chunk of chunks(Object.entries(tests), 100)) {
142146
await compareDownstreamResponse(test.downstream_response, response);
143147
return {
144148
title,
149+
test,
145150
skipped: false
146151
};
147152
} catch (error) {
@@ -150,6 +155,7 @@ for (const chunk of chunks(Object.entries(tests), 100)) {
150155
} else {
151156
return {
152157
title,
158+
test,
153159
skipped: true
154160
}
155161
}
@@ -168,6 +174,7 @@ for (const chunk of chunks(Object.entries(tests), 100)) {
168174
await compareDownstreamResponse(test.downstream_response, response);
169175
return {
170176
title,
177+
test,
171178
skipped: false
172179
};
173180
} catch (error) {
@@ -177,6 +184,7 @@ for (const chunk of chunks(Object.entries(tests), 100)) {
177184
} else {
178185
return {
179186
title,
187+
test,
180188
skipped: true
181189
}
182190
}
@@ -191,6 +199,7 @@ let passed = 0;
191199
const failed = [];
192200
const green = '\u001b[32m';
193201
const red = '\u001b[31m';
202+
const reset = '\u001b[0m';
194203
const white = '\u001b[39m';
195204
const info = '\u2139';
196205
const tick = '\u2714';
@@ -199,16 +208,20 @@ for (const result of results) {
199208
if (result.status === 'fulfilled') {
200209
passed += 1;
201210
if (result.value.skipped) {
202-
if (local) {
203-
console.log(white, info, `Skipped as test marked to only run on Fastly Compute: ${result.value.title}`, white);
211+
if (!result.value.title.includes(filter)) {
212+
console.log(white, info, `Skipped by test filter: ${result.value.title}`, reset);
213+
} else if (local && !result.value.test.environments.includes("viceroy")) {
214+
console.log(white, info, `Skipped as test marked to only run on Fastly Compute: ${result.value.title}`, reset);
215+
} else if (!local && !result.value.test.environments.includes("compute")) {
216+
console.log(white, info, `Skipped as test marked to only run on local server: ${result.value.title}`, reset);
204217
} else {
205-
console.log(white, info, `Skipped as test marked to only run on local server: ${result.value.title}`, white);
218+
console.log(white, info, `Skipped due to no environments set: ${result.value.title}`, reset);
206219
}
207220
} else {
208-
console.log(green, tick, result.value.title, white);
221+
console.log(green, tick, result.value.title, reset);
209222
}
210223
} else {
211-
console.log(red, cross, result.reason, white);
224+
console.log(red, cross, result.reason, reset);
212225
failed.push(result.reason)
213226
}
214227
}
@@ -219,7 +232,7 @@ if (failed.length) {
219232
core.startGroup('Failed tests')
220233

221234
for (const result of failed) {
222-
console.log(red, cross, result, white);
235+
console.log(red, cross, result, reset);
223236
}
224237

225238
core.endGroup()

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"scripts": {
2929
"test": "npm run test:types && npm run test:cli",
3030
"test:cli": "brittle --bail integration-tests/cli/**.test.js",
31+
"test:integration": "node ./integration-tests/js-compute/test.js",
3132
"test:types": "tsd",
3233
"build": "make -j8 -C runtime/js-compute-runtime && cp runtime/js-compute-runtime/*.wasm .",
3334
"build:debug": "DEBUG=true make -j8 -C runtime/js-compute-runtime && cp runtime/js-compute-runtime/*.wasm .",

runtime/fastly/builtins/cache-core.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ bool CacheEntry::body(JSContext *cx, unsigned argc, JS::Value *vp) {
554554
// options parameter is optional
555555
// options is meant to be an object with an optional `start` and `end` fields, both which can be
556556
// Numbers.
557-
ENGINE->dump_value(options_val, stdout);
558557
if (!options_val.isUndefined()) {
559558
if (!options_val.isObject()) {
560559
JS_ReportErrorASCII(cx, "options argument must be an object");

runtime/fastly/builtins/fetch/request-response.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ bool RequestOrResponse::process_pending_request(JSContext *cx, FastlyHandle hand
228228
}
229229

230230
bool RequestOrResponse::is_instance(JSObject *obj) {
231-
return Request::is_instance(obj) || Response::is_instance(obj) ||
232-
SimpleCacheEntry::is_instance(obj) || KVStoreEntry::is_instance(obj) ||
233-
CacheEntry::is_instance(obj);
231+
return Request::is_instance(obj) || Response::is_instance(obj) || KVStoreEntry::is_instance(obj);
234232
}
235233

236234
uint32_t RequestOrResponse::handle(JSObject *obj) {

runtime/fastly/handler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ void handle_incoming(host_api::Request req) {
5353
if (JS_IsExceptionPending(ENGINE->cx())) {
5454
ENGINE->dump_pending_exception("evaluating code");
5555
} else if (!success) {
56+
if (ENGINE->has_pending_async_tasks()) {
57+
fprintf(stderr, "Event loop terminated with async tasks pending. "
58+
"Use FetchEvent#waitUntil to extend the service's lifetime "
59+
"if needed.\n");
60+
}
5661
abort();
5762
}
5863

runtime/js-compute-runtime/builtins/cache-core.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ bool CacheEntry::body(JSContext *cx, unsigned argc, JS::Value *vp) {
548548
// options parameter is optional
549549
// options is meant to be an object with an optional `start` and `end` fields, both which can be
550550
// Numbers.
551-
dump_value(cx, options_val, stdout);
552551
if (!options_val.isUndefined()) {
553552
if (!options_val.isObject()) {
554553
JS_ReportErrorASCII(cx, "options argument must be an object");

tests/wpt-harness/build-wpt-runtime.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ inputs=(
1010
)
1111

1212
cat "${inputs[@]}" > "${script_dir}/wpt-test-runner.js"
13-
node "${script_dir}/../../js-compute-runtime-cli.js" "${script_dir}/wpt-test-runner.js" wpt-runtime.wasm
13+
node "${script_dir}/../../js-compute-runtime-cli.js" "${script_dir}/wpt-test-runner.js" "$@" wpt-runtime.wasm

0 commit comments

Comments
 (0)