Skip to content

Commit

Permalink
KV Store v2 (#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Oct 31, 2024
1 parent b328546 commit 3180a50
Show file tree
Hide file tree
Showing 26 changed files with 1,829 additions and 542 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defaults:
shell: bash
env:
# Note: when updated, also update version in ensure-cargo-installs
viceroy_version: 0.12.0
viceroy_version: 0.12.1
# Note: when updated, also update version in ensure-cargo-installs ! AND ! release-please.yml
wasm-tools_version: 1.216.0
fastly-cli_version: 10.13.3
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
matrix:
include:
- crate: viceroy
version: 0.12.0 # Note: workflow-level env vars can't be used in matrix definitions
version: 0.12.1 # Note: workflow-level env vars can't be used in matrix definitions
options: ""
- crate: wasm-tools
version: 1.216.0 # Note: workflow-level env vars can't be used in matrix definitions
Expand Down
15 changes: 14 additions & 1 deletion integration-tests/js-compute/fixtures/app/src/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ export function assertDoesNotThrow(func) {
}
}

export { deepEqual as deepStrictEqual };
export function deepStrictEqual(a, b) {
if (!deepEqual(a, b)) {
throw new Error(`Expected ${a} to equal ${b}`);
}
}

export function deepEqual(a, b) {
var aKeys;
Expand All @@ -157,6 +161,15 @@ export function deepEqual(a, b) {
if (b === null || typeB !== 'object') {
return false;
}
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) {
if (!deepEqual(a[i], b[i])) {
return false;
}
}
return true;
}
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) {
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions integration-tests/js-compute/fixtures/app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import './console.js';
import './crypto.js';
import './device.js';
import './dictionary.js';
import './dynamic-backend.js';
import './edge-rate-limiter.js';
import './env.js';
import './fanout.js';
Expand All @@ -27,7 +26,6 @@ import './fetch-errors.js';
import './geoip.js';
import './headers.js';
import './include-bytes.js';
import './kv-store.js';
import './logger.js';
import './manual-framing-headers.js';
import './missing-backend.js';
Expand Down
175 changes: 0 additions & 175 deletions integration-tests/js-compute/fixtures/app/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -934,97 +934,6 @@
"body": "ok"
}
},
"GET /backend/timeout": {
"environments": ["compute"],
"downstream_response": {
"status": 200,
"body": "ok"
}
},
"GET /implicit-dynamic-backend/dynamic-backends-disabled": {},
"GET /implicit-dynamic-backend/dynamic-backends-enabled": {},
"GET /implicit-dynamic-backend/dynamic-backends-enabled-called-twice": {},
"GET /explicit-dynamic-backend/dynamic-backends-enabled-all-fields": {},
"GET /explicit-dynamic-backend/dynamic-backends-enabled-minimal-fields": {},
"GET /backend/interface": {},
"GET /backend/constructor/called-as-regular-function": {},
"GET /backend/constructor/empty-parameter": {},
"GET /backend/constructor/parameter-not-an-object": {},
"GET /backend/constructor/parameter-name-property-null": {},
"GET /backend/constructor/parameter-name-property-undefined": {},
"GET /backend/constructor/parameter-name-property-too-long": {},
"GET /backend/constructor/parameter-name-property-empty-string": {},
"GET /backend/constructor/parameter-name-property-calls-7.1.17-ToString": {},
"GET /backend/constructor/parameter-target-property-null": {},
"GET /backend/constructor/parameter-target-property-undefined": {},
"GET /backend/constructor/parameter-target-property-empty-string": {},
"GET /backend/constructor/parameter-target-property-calls-7.1.17-ToString": {},
"GET /backend/constructor/parameter-target-property-valid-host": {},
"GET /backend/constructor/parameter-target-property-invalid-host": {},
"GET /backend/constructor/parameter-ciphers-property-empty-string": {},
"GET /backend/constructor/parameter-ciphers-property-invalid-cipherlist-string": {},
"GET /backend/constructor/parameter-ciphers-property-valid-cipherlist-strings-supported-by-fastly": {},
"GET /backend/constructor/parameter-ciphers-property-valid-cipherlist-strings-but-not-supported-by-fastly": {},
"GET /backend/constructor/parameter-ciphers-property-calls-7.1.17-ToString": {},
"GET /backend/constructor/parameter-hostOverride-property-empty-string": {},
"GET /backend/constructor/parameter-hostOverride-property-calls-7.1.17-ToString": {},
"GET /backend/constructor/parameter-hostOverride-property-valid-string": {},
"GET /backend/constructor/parameter-connectTimeout-property-negative-number": {},
"GET /backend/constructor/parameter-connectTimeout-property-too-big": {},
"GET /backend/constructor/parameter-connectTimeout-property-calls-7.1.4-ToNumber": {},
"GET /backend/constructor/parameter-connectTimeout-property-valid-number": {},
"GET /backend/constructor/parameter-firstByteTimeout-property-negative-number": {},
"GET /backend/constructor/parameter-firstByteTimeout-property-too-big": {},
"GET /backend/constructor/parameter-firstByteTimeout-property-calls-7.1.4-ToNumber": {},
"GET /backend/constructor/parameter-firstByteTimeout-property-valid-number": {},
"GET /backend/constructor/parameter-firstByteTimeout-property-invalid-number": {},
"GET /backend/constructor/parameter-betweenBytesTimeout-property-negative-number": {},
"GET /backend/constructor/parameter-betweenBytesTimeout-property-too-big": {},
"GET /backend/constructor/parameter-betweenBytesTimeout-property-calls-7.1.4-ToNumber": {},
"GET /backend/constructor/parameter-betweenBytesTimeout-property-valid-number": {},
"GET /backend/constructor/parameter-useSSL-property-valid-boolean": {},
"GET /backend/constructor/parameter-dontPool-property-valid-boolean": {},
"GET /backend/constructor/parameter-tlsMinVersion-property-nan": {},
"GET /backend/constructor/parameter-tlsMinVersion-property-invalid-number": {},
"GET /backend/constructor/parameter-tlsMinVersion-property-calls-7.1.4-ToNumber": {},
"GET /backend/constructor/parameter-tlsMinVersion-property-valid-number": {},
"GET /backend/constructor/parameter-tlsMinVersion-greater-than-tlsMaxVersion": {},
"GET /backend/constructor/parameter-tlsMaxVersion-property-nan": {},
"GET /backend/constructor/parameter-tlsMaxVersion-property-invalid-number": {},
"GET /backend/constructor/parameter-tlsMaxVersion-property-calls-7.1.4-ToNumber": {},
"GET /backend/constructor/parameter-tlsMaxVersion-property-valid-number": {},
"GET /backend/constructor/parameter-certificateHostname-property-empty-string": {},
"GET /backend/constructor/parameter-certificateHostname-property-calls-7.1.17-ToString": {},
"GET /backend/constructor/parameter-certificateHostname-property-valid-string": {},
"GET /backend/constructor/parameter-caCertificate-property-empty-string": {},
"GET /backend/constructor/parameter-caCertificate-property-calls-7.1.17-ToString": {},
"GET /backend/constructor/parameter-caCertificate-property-valid-string": {},
"GET /backend/constructor/parameter-sniHostname-property-empty-string": {},
"GET /backend/constructor/parameter-sniHostname-property-calls-7.1.17-ToString": {},
"GET /backend/constructor/parameter-sniHostname-property-valid-string": {},
"GET /backend/constructor/parameter-clientCertificate-property-invalid": {},
"GET /backend/constructor/parameter-clientCertificate-certificate-property-missing": {},
"GET /backend/constructor/parameter-clientCertificate-certificate-property-invalid": {},
"GET /backend/constructor/parameter-clientCertificate-key-property-missing": {},
"GET /backend/constructor/parameter-clientCertificate-key-property-invalid": {},
"GET /backend/constructor/parameter-clientCertificate-key-property-fake": {},
"GET /backend/constructor/parameter-clientCertificate-valid": {},
"GET /backend/constructor/parameter-grpc-property-falsy": {},
"GET /backend/constructor/parameter-grpc-enabled": {},
"GET /backend/constructor/http-keepalive-invalid": {},
"GET /backend/constructor/http-keepalive": {},
"GET /backend/constructor/tcp-keepalive-invalid": {},
"GET /backend/constructor/tcp-keepalive": {},
"GET /backend/set-default-backend-configuration": {},
"GET /backend/health/called-as-constructor-function": {},
"GET /backend/health/empty-parameter": {},
"GET /backend/health/parameter-calls-7.1.17-ToString": {},
"GET /backend/health/parameter-invalid": {},
"GET /backend/health/happy-path-backend-exists": {},
"GET /backend/health/happy-path-backend-does-not-exist": {},
"GET /backend/port-ip-defined": {},
"GET /backend/port-ip-cached": {},
"GET /backend/props": {},
"GET /dictionary/exposed-as-global": {},
"GET /dictionary/interface": {},
"GET /dictionary/constructor/called-as-regular-function": {},
Expand Down Expand Up @@ -1080,90 +989,6 @@
"environments": ["compute"]
},
"GET /includeBytes": {},
"GET /kv-store/exposed-as-global": {},
"GET /kv-store/interface": {},
"GET /kv-store/constructor/called-as-regular-function": {},
"GET /kv-store/constructor/parameter-calls-7.1.17-ToString": {},
"GET /kv-store/constructor/empty-parameter": {},
"GET /kv-store/constructor/found-store": {},
"GET /kv-store/constructor/missing-store": {},
"GET /kv-store/constructor/invalid-name": {},
"GET /kv-store/put/called-as-constructor": {},
"GET /kv-store/put/called-unbound": {},
"GET /kv-store/put/key-parameter-calls-7.1.17-ToString": {},
"GET /kv-store/put/key-parameter-not-supplied": {},
"GET /kv-store/put/key-parameter-empty-string": {},
"GET /kv-store/put/key-parameter-1024-character-string": {},
"GET /kv-store/put/key-parameter-1025-character-string": {},
"GET /kv-store/put/key-parameter-containing-newline": {},
"GET /kv-store/put/key-parameter-containing-carriage-return": {},
"GET /kv-store/put/key-parameter-starting-with-well-known-acme-challenge": {},
"GET /kv-store/put/key-parameter-single-dot": {},
"GET /kv-store/put/key-parameter-double-dot": {},
"GET /kv-store/put/key-parameter-containing-special-characters": {},
"GET /kv-store/put/value-parameter-as-undefined": {},
"GET /kv-store/put/value-parameter-not-supplied": {},
"GET /kv-store/put/value-parameter-readablestream-empty": {},
"GET /kv-store/put/value-parameter-readablestream-under-30mb": {},
"GET /kv-store/put/value-parameter-readablestream-over-30mb": {},
"GET /kv-store/put/value-parameter-readablestream-locked": {},
"GET /kv-store/put/value-parameter-URLSearchParams": {},
"GET /kv-store/put/value-parameter-strings": {},
"GET /kv-store/put/value-parameter-string-over-30mb": {},
"GET /kv-store/put/value-parameter-calls-7.1.17-ToString": {},
"GET /kv-store/put/value-parameter-buffer": {},
"GET /kv-store/put/value-parameter-arraybuffer": {},
"GET /kv-store/put/value-parameter-typed-arrays": {},
"GET /kv-store/put/value-parameter-dataview": {},
"POST /kv-store/put/request-body": {
"environments": ["compute"],
"downstream_request": {
"method": "POST",
"pathname": "/kv-store/put/request-body",
"headers": ["Content-Type", "application/json"],
"body": "hello world!"
}
},
"GET /kv-store/delete/called-as-constructor": {},
"GET /kv-store/delete/called-unbound": {},
"GET /kv-store/delete/key-parameter-calls-7.1.17-ToString": {},
"GET /kv-store/delete/key-parameter-not-supplied": {},
"GET /kv-store/delete/key-parameter-empty-string": {},
"GET /kv-store/delete/key-parameter-1024-character-string": {},
"GET /kv-store/delete/key-parameter-1025-character-string": {},
"GET /kv-store/delete/key-parameter-containing-newline": {},
"GET /kv-store/delete/key-parameter-containing-carriage-return": {},
"GET /kv-store/delete/key-parameter-starting-with-well-known-acme-challenge": {},
"GET /kv-store/delete/key-parameter-single-dot": {},
"GET /kv-store/delete/key-parameter-double-dot": {},
"GET /kv-store/delete/key-parameter-containing-special-characters": {},
"GET /kv-store/delete/key-does-not-exist-returns-undefined": {},
"GET /kv-store/delete/key-exists": {},
"GET /kv-store/delete/delete-key-twice": {},
"GET /kv-store/delete/multiple-deletes-at-once": {},
"GET /kv-store/get/called-as-constructor": {},
"GET /kv-store/get/called-unbound": {},
"GET /kv-store/get/key-parameter-calls-7.1.17-ToString": {},
"GET /kv-store/get/key-parameter-not-supplied": {},
"GET /kv-store/get/key-parameter-empty-string": {},
"GET /kv-store/get/key-parameter-1024-character-string": {},
"GET /kv-store/get/key-parameter-1025-character-string": {},
"GET /kv-store/get/key-parameter-containing-newline": {},
"GET /kv-store/get/key-parameter-containing-carriage-return": {},
"GET /kv-store/get/key-parameter-starting-with-well-known-acme-challenge": {},
"GET /kv-store/get/key-parameter-single-dot": {},
"GET /kv-store/get/key-parameter-double-dot": {},
"GET /kv-store/get/key-parameter-containing-special-characters": {},
"GET /kv-store/get/key-does-not-exist-returns-null": {},
"GET /kv-store/get/key-exists": {},
"GET /kv-store/get/multiple-lookups-at-once": {},
"GET /kv-store-entry/interface": {},
"GET /kv-store-entry/text/valid": {},
"GET /kv-store-entry/json/valid": {},
"GET /kv-store-entry/json/invalid": {},
"GET /kv-store-entry/arrayBuffer/valid": {},
"GET /kv-store-entry/body": {},
"GET /kv-store-entry/bodyUsed": {},
"GET /logger": {
"environments": ["viceroy"],
"logs": ["ComputeLog :: Hello!"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "js-test-app"
service_id = ""

[scripts]
build = "node ../../../../js-compute-runtime-cli.js --enable-experimental-high-resolution-time-methods --enable-experimental-top-level-await src/index.js"
build = "node ../../../../js-compute-runtime-cli.js --enable-experimental-high-resolution-time-methods --module-mode src/index.js"

[local_server]

Expand Down
63 changes: 63 additions & 0 deletions integration-tests/js-compute/fixtures/module-mode/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node

import { $ as zx } from 'zx';
import { argv } from 'node:process';

const serviceName = argv[2];

const startTime = Date.now();

if (process.env.FASTLY_API_TOKEN === undefined) {
zx.verbose = false;
try {
process.env.FASTLY_API_TOKEN = String(
await zx`fastly profile token --quiet`,
).trim();
} catch {
console.error(
'No environment variable named FASTLY_API_TOKEN has been set and no default fastly profile exists.',
);
console.error(
'In order to run the tests, either create a fastly profile using `fastly profile create` or export a fastly token under the name FASTLY_API_TOKEN',
);
process.exit(1);
}
zx.verbose = true;
}

// Setup KV Stores
{
let stores = await (async function () {
try {
return JSON.parse(
await zx`fastly kv-store list --quiet --json --token $FASTLY_API_TOKEN`,
);
} catch {
return [];
}
})();

const existing = stores.Data.find(
({ Name }) => Name === `example-test-kv-store`,
);
// For somereason the StarlingMonkey version of this contains "ID" instead of "StoreID"
const STORE_ID = existing?.StoreID || existing?.ID;
if (!STORE_ID) {
process.env.STORE_ID = JSON.parse(
await zx`fastly kv-store create --quiet --name='example-test-kv-store' --json --token $FASTLY_API_TOKEN`,
).id;
} else {
process.env.STORE_ID = STORE_ID;
}
try {
await zx`fastly resource-link create --service-name ${serviceName} --version latest --resource-id $STORE_ID --token $FASTLY_API_TOKEN --autoclone`;
} catch (e) {
if (!e.message.includes('Duplicate record')) throw e;
}
}

await zx`fastly service-version activate --service-name ${serviceName} --version latest --token $FASTLY_API_TOKEN`;

console.log(
`Set up has finished! Took ${(Date.now() - startTime) / 1000} seconds to complete`,
);
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ export function assertDoesNotThrow(func) {
}
}

export { deepEqual as deepStrictEqual };
export function deepStrictEqual(a, b) {
if (!deepEqual(a, b)) {
throw new Error(
`Expected ${a} to equal ${b}, got ${JSON.stringify(a, null, 2)}`,
);
}
}

export function deepEqual(a, b) {
var aKeys;
Expand All @@ -157,6 +163,15 @@ export function deepEqual(a, b) {
if (b === null || typeB !== 'object') {
return false;
}
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) {
if (!deepEqual(a[i], b[i])) {
return false;
}
}
return true;
}
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) {
return false;
}
Expand Down
Loading

0 comments on commit 3180a50

Please sign in to comment.