Skip to content

Commit 299e782

Browse files
authored
Rework the sdk-tests (#115)
Rework the integration tests to require less information in `sdk-test-config.json`, and to use a local viceroy instance in place of a long-running c@e instance.
1 parent 09432fc commit 299e782

File tree

26 files changed

+360
-106
lines changed

26 files changed

+360
-106
lines changed

.github/actions/compute-sdk-test/dist/main.js

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7428,29 +7428,62 @@ const compareDownstreamResponse = __nccwpck_require__(193);
74287428

74297429

74307430
// Get our config from the Github Action
7431-
const configRelativePath = `./integration-tests/js-compute/sdk-test-config.json`;
7431+
const integrationTestBase = `./integration-tests/js-compute`;
7432+
const fixtureBase = `${integrationTestBase}/fixtures`;
7433+
const configRelativePath = `${integrationTestBase}/sdk-test-config.json`;
7434+
74327435
console.info(`Parsing SDK Test config: ${configRelativePath}`);
74337436
const configAbsolutePath = path.resolve(configRelativePath);
74347437
const config = JSON.parse(fs.readFileSync(configAbsolutePath));
74357438
console.info('Running the SDK Config:');
74367439
console.log(`${JSON.stringify(config, null, 2)}`);
74377440

7441+
async function spawnViceroy(testName, viceroyAddr) {
7442+
const wasmPath = `${fixtureBase}/${testName}/${testName}.wasm`;
7443+
const fastlyTomlPath = `${fixtureBase}/${testName}/fastly.toml`;
7444+
7445+
let viceroy = new Viceroy();
7446+
await viceroy.spawn(wasmPath, {
7447+
config: fastlyTomlPath,
7448+
addr: viceroyAddr
7449+
});
7450+
7451+
return viceroy;
7452+
}
7453+
7454+
function buildTest(testName, backendAddr) {
7455+
console.info(`Compiling the fixture for: ${testName} ...`);
7456+
7457+
childProcess.execSync(
7458+
`./integration-tests/js-compute/build-one.sh ${testName}`,
7459+
{
7460+
stdio: 'inherit'
7461+
}
7462+
);
7463+
7464+
childProcess.execSync(
7465+
`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`,
7466+
{
7467+
stdio: 'inherit'
7468+
}
7469+
);
7470+
}
7471+
74387472
// Our main task, in which we compile and run tests
74397473
const mainAsyncTask = async () => {
74407474
// Iterate through our config and compile our wasm modules
74417475
const modules = config.modules;
74427476
const moduleKeys = Object.keys(modules);
74437477

7444-
moduleKeys.forEach(key => {
7445-
const module = modules[key];
7446-
console.info(`Compiling the fixture for: ${key} ...`);
7447-
const moduleBuildStdout = childProcess.execSync(
7448-
module.build,
7449-
{
7450-
stdio: 'inherit'
7451-
}
7452-
);
7453-
});
7478+
const backendAddr = '127.0.0.1:8082';
7479+
7480+
// build all the tests
7481+
moduleKeys.forEach(testName => buildTest(testName, backendAddr));
7482+
buildTest('backend', backendAddr);
7483+
7484+
// Start up the local backend
7485+
console.info(`Starting the generic backend on ${backendAddr}`);
7486+
let backend = await spawnViceroy('backend', backendAddr);
74547487

74557488
console.info(`Running the Viceroy environment tests ...`);
74567489

@@ -7469,6 +7502,7 @@ const mainAsyncTask = async () => {
74697502
try {
74707503
await compareUpstreamRequest(configRequest, req, isDownstreamResponseHandled);
74717504
} catch (err) {
7505+
await backend.kill();
74727506
await viceroy.kill();
74737507
console.error(`[LocalUpstreamRequest (${localUpstreamRequestNumber})] ${err.message}`);
74747508
process.exit(1);
@@ -7477,19 +7511,24 @@ const mainAsyncTask = async () => {
74777511

74787512
// Iterate through the module tests, and run the Viceroy tests
74797513
for (const moduleKey of moduleKeys) {
7514+
const testBase = `${fixtureBase}/${moduleKey}`;
7515+
7516+
// created/used by ./integration-tests/js-compute/build-one.sh
7517+
const fastlyTomlPath = `${testBase}/fastly.toml`;
7518+
const wasmPath = `${testBase}/${moduleKey}.wasm`;
7519+
74807520
const module = modules[moduleKey];
74817521
const moduleTestKeys = Object.keys(module.tests);
74827522
console.info(`Running tests for the module: ${moduleKey} ...`);
74837523

74847524
// Spawn a new viceroy instance for the module
74857525
viceroy = new Viceroy();
74867526
const viceroyAddr = '127.0.0.1:8080';
7487-
await viceroy.spawn(module.wasm_path, {
7488-
config: module.fastly_toml_path,
7527+
await viceroy.spawn(wasmPath, {
7528+
config: fastlyTomlPath,
74897529
addr: viceroyAddr
74907530
})
74917531

7492-
74937532
for (const testKey of moduleTestKeys) {
74947533
const test = module.tests[testKey];
74957534

@@ -7521,6 +7560,7 @@ const mainAsyncTask = async () => {
75217560
});
75227561
} catch(error) {
75237562
await upstreamServer.close();
7563+
await backend.kill();
75247564
await viceroy.kill();
75257565
console.error(error);
75267566
process.exit(1);
@@ -7538,6 +7578,7 @@ const mainAsyncTask = async () => {
75387578
if (!viceroy.logs.includes(log)) {
75397579
console.error(`[Logs: log not found] Expected: ${log}`);
75407580
await upstreamServer.close();
7581+
await backend.kill();
75417582
await viceroy.kill();
75427583
process.exit(1);
75437584
}
@@ -7551,6 +7592,7 @@ const mainAsyncTask = async () => {
75517592
} catch (err) {
75527593
console.error(err.message);
75537594
await upstreamServer.close();
7595+
await backend.kill();
75547596
await viceroy.kill();
75557597
process.exit(1);
75567598
}
@@ -7573,14 +7615,21 @@ const mainAsyncTask = async () => {
75737615
try {
75747616
await viceroy.kill();
75757617
} catch(e) {
7576-
console.error('Could not kill Viceory. Error Below:');
7618+
console.error('Could not kill test Viceroy instance. Error Below:');
75777619
console.error(e);
75787620
process.exit(1);
75797621
}
75807622
};
75817623

75827624
// Viceroy is done! Close our upstream server and things
75837625
await upstreamServer.close();
7626+
try {
7627+
await backend.kill();
7628+
} catch(e) {
7629+
console.error('Could not kill backend Viceroy instance. Error Below:');
7630+
console.error(e);
7631+
process.exit(1);
7632+
}
75847633

75857634
// Check if we have C@E Environement tests
75867635
let shouldRunComputeTests = moduleKeys.some(moduleKey => {

.github/actions/compute-sdk-test/main.js

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,62 @@ const compareDownstreamResponse = require('./src/compare-downstream-response.js'
3131

3232

3333
// Get our config from the Github Action
34-
const configRelativePath = `./integration-tests/js-compute/sdk-test-config.json`;
34+
const integrationTestBase = `./integration-tests/js-compute`;
35+
const fixtureBase = `${integrationTestBase}/fixtures`;
36+
const configRelativePath = `${integrationTestBase}/sdk-test-config.json`;
37+
3538
console.info(`Parsing SDK Test config: ${configRelativePath}`);
3639
const configAbsolutePath = path.resolve(configRelativePath);
3740
const config = JSON.parse(fs.readFileSync(configAbsolutePath));
3841
console.info('Running the SDK Config:');
3942
console.log(`${JSON.stringify(config, null, 2)}`);
4043

44+
async function spawnViceroy(testName, viceroyAddr) {
45+
const wasmPath = `${fixtureBase}/${testName}/${testName}.wasm`;
46+
const fastlyTomlPath = `${fixtureBase}/${testName}/fastly.toml`;
47+
48+
let viceroy = new Viceroy();
49+
await viceroy.spawn(wasmPath, {
50+
config: fastlyTomlPath,
51+
addr: viceroyAddr
52+
});
53+
54+
return viceroy;
55+
}
56+
57+
function buildTest(testName, backendAddr) {
58+
console.info(`Compiling the fixture for: ${testName} ...`);
59+
60+
childProcess.execSync(
61+
`./integration-tests/js-compute/build-one.sh ${testName}`,
62+
{
63+
stdio: 'inherit'
64+
}
65+
);
66+
67+
childProcess.execSync(
68+
`./integration-tests/js-compute/replace-host.sh ${testName} http://${backendAddr}`,
69+
{
70+
stdio: 'inherit'
71+
}
72+
);
73+
}
74+
4175
// Our main task, in which we compile and run tests
4276
const mainAsyncTask = async () => {
4377
// Iterate through our config and compile our wasm modules
4478
const modules = config.modules;
4579
const moduleKeys = Object.keys(modules);
4680

47-
moduleKeys.forEach(key => {
48-
const module = modules[key];
49-
console.info(`Compiling the fixture for: ${key} ...`);
50-
const moduleBuildStdout = childProcess.execSync(
51-
module.build,
52-
{
53-
stdio: 'inherit'
54-
}
55-
);
56-
});
81+
const backendAddr = '127.0.0.1:8082';
82+
83+
// build all the tests
84+
moduleKeys.forEach(testName => buildTest(testName, backendAddr));
85+
buildTest('backend', backendAddr);
86+
87+
// Start up the local backend
88+
console.info(`Starting the generic backend on ${backendAddr}`);
89+
let backend = await spawnViceroy('backend', backendAddr);
5790

5891
console.info(`Running the Viceroy environment tests ...`);
5992

@@ -72,6 +105,7 @@ const mainAsyncTask = async () => {
72105
try {
73106
await compareUpstreamRequest(configRequest, req, isDownstreamResponseHandled);
74107
} catch (err) {
108+
await backend.kill();
75109
await viceroy.kill();
76110
console.error(`[LocalUpstreamRequest (${localUpstreamRequestNumber})] ${err.message}`);
77111
process.exit(1);
@@ -80,19 +114,24 @@ const mainAsyncTask = async () => {
80114

81115
// Iterate through the module tests, and run the Viceroy tests
82116
for (const moduleKey of moduleKeys) {
117+
const testBase = `${fixtureBase}/${moduleKey}`;
118+
119+
// created/used by ./integration-tests/js-compute/build-one.sh
120+
const fastlyTomlPath = `${testBase}/fastly.toml`;
121+
const wasmPath = `${testBase}/${moduleKey}.wasm`;
122+
83123
const module = modules[moduleKey];
84124
const moduleTestKeys = Object.keys(module.tests);
85125
console.info(`Running tests for the module: ${moduleKey} ...`);
86126

87127
// Spawn a new viceroy instance for the module
88128
viceroy = new Viceroy();
89129
const viceroyAddr = '127.0.0.1:8080';
90-
await viceroy.spawn(module.wasm_path, {
91-
config: module.fastly_toml_path,
130+
await viceroy.spawn(wasmPath, {
131+
config: fastlyTomlPath,
92132
addr: viceroyAddr
93133
})
94134

95-
96135
for (const testKey of moduleTestKeys) {
97136
const test = module.tests[testKey];
98137

@@ -124,6 +163,7 @@ const mainAsyncTask = async () => {
124163
});
125164
} catch(error) {
126165
await upstreamServer.close();
166+
await backend.kill();
127167
await viceroy.kill();
128168
console.error(error);
129169
process.exit(1);
@@ -141,6 +181,7 @@ const mainAsyncTask = async () => {
141181
if (!viceroy.logs.includes(log)) {
142182
console.error(`[Logs: log not found] Expected: ${log}`);
143183
await upstreamServer.close();
184+
await backend.kill();
144185
await viceroy.kill();
145186
process.exit(1);
146187
}
@@ -154,6 +195,7 @@ const mainAsyncTask = async () => {
154195
} catch (err) {
155196
console.error(err.message);
156197
await upstreamServer.close();
198+
await backend.kill();
157199
await viceroy.kill();
158200
process.exit(1);
159201
}
@@ -176,14 +218,21 @@ const mainAsyncTask = async () => {
176218
try {
177219
await viceroy.kill();
178220
} catch(e) {
179-
console.error('Could not kill Viceory. Error Below:');
221+
console.error('Could not kill test Viceroy instance. Error Below:');
180222
console.error(e);
181223
process.exit(1);
182224
}
183225
};
184226

185227
// Viceroy is done! Close our upstream server and things
186228
await upstreamServer.close();
229+
try {
230+
await backend.kill();
231+
} catch(e) {
232+
console.error('Could not kill backend Viceroy instance. Error Below:');
233+
console.error(e);
234+
process.exit(1);
235+
}
187236

188237
// Check if we have C@E Environement tests
189238
let shouldRunComputeTests = moduleKeys.some(moduleKey => {

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Integration Tests build output
44
integration-tests/**/fixtures/**/*.tar.gz
5-
integration-tests/**/fixtures/**/pkg/**/fastly.toml
5+
integration-tests/**/fixtures/**/fastly.toml
66
integration-tests/**/fixtures/**/*.wasm
77
integration-tests/**/fixtures/**/*.js
88
integration-tests/**/fixtures/**/*.js.map
@@ -133,4 +133,4 @@ dist
133133
# Rust Git Ignore
134134
/target
135135
/dist
136-
.DS_Store
136+
.DS_Store
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [ "$#" -lt 1 ]; then
6+
echo "Usage: $0 <test>"
7+
exit 1
8+
fi
9+
10+
test="$1"
11+
12+
cd "$(dirname "${BASH_SOURCE[0]}")"
13+
14+
npm install -s
15+
16+
if [ -f "fixtures/$test/$test.ts" ]; then
17+
npm run -s build:test --test="$test"
18+
else
19+
echo "Skipping typescript conversion for fixtures/$test/$test.js"
20+
fi
21+
22+
../../target/release/js-compute-runtime "fixtures/$test/$test.js" "fixtures/$test/$test.wasm"

integration-tests/js-compute/fixtures/async-select/fastly.toml renamed to integration-tests/js-compute/fixtures/async-select/fastly.toml.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ service_id = ""
1313
[local_server.backends]
1414

1515
[local_server.backends.TheOrigin]
16-
url = "https://compute-sdk-test-backend.edgecompute.app/"
16+
url = "JS_COMPUTE_TEST_BACKEND/"
1717

1818
[local_server.backends.TheOrigin2]
19-
url = "https://compute-sdk-test-backend.edgecompute.app/"
19+
url = "JS_COMPUTE_TEST_BACKEND/"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!backend.js

0 commit comments

Comments
 (0)