Skip to content

Commit

Permalink
keep worker alive (#554)
Browse files Browse the repository at this point in the history
* do not terminate worker on chain close

* teardown timeout

* update node test

* bump

* use latest vitest

* fix

* extend expect

* update endpoints
  • Loading branch information
ermalkaleci committed Nov 23, 2023
1 parent b590f31 commit b724995
Show file tree
Hide file tree
Showing 26 changed files with 431 additions and 191 deletions.
2 changes: 1 addition & 1 deletion configs/statemine.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
endpoint: wss://statemine-rpc.polkadot.io
endpoint: wss://statemine-rpc.dwellir.com
mock-signature-host: true
block: ${env.STATEMINE_BLOCK_NUMBER}
db: ./db.sqlite
Expand Down
2 changes: 1 addition & 1 deletion configs/statemint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
endpoint: wss://statemint-rpc.polkadot.io
endpoint: wss://statemint-rpc.dwellir.com
mock-signature-host: true
block: ${env.STATEMINT_BLOCK_NUMBER}
db: ./db.sqlite
Expand Down
2 changes: 1 addition & 1 deletion executor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion executor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chopsticks-executor"
version = "0.9.3-1"
version = "0.9.3-2"
description = "Chopsticks executor"
repository = "https://github.com/AcalaNetwork/chopsticks"
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion executor/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@acala-network/chopsticks-executor",
"description": "Chopsticks executor",
"version": "0.9.3-1",
"version": "0.9.3-2",
"license": "Apache-2.0",
"type": "module",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"unplugin-swc": "^1.4.3",
"vite-tsconfig-paths": "^4.2.1",
"vitepress": "^1.0.0-rc.23",
"vitest": "^0.34.6",
"vitest": "^1.0.0-beta.5",
"wasm-pack": "^0.12.1"
}
}
4 changes: 2 additions & 2 deletions packages/chopsticks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks",
"version": "0.9.3-1",
"version": "0.9.3-2",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"bin": "./chopsticks.cjs",
Expand Down Expand Up @@ -41,7 +41,7 @@
"@types/ws": "^8.5.10",
"@types/yargs": "^17.0.32",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
"vitest": "^1.0.0-beta.5"
},
"files": [
"dist/esm/**",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks-core",
"version": "0.9.3-1",
"version": "0.9.3-2",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"type": "module",
Expand Down Expand Up @@ -34,7 +34,7 @@
"@swc/core": "^1.3.99",
"@types/lodash": "^4.14.202",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
"vitest": "^1.0.0-beta.5"
},
"files": [
"dist/esm/**",
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/blockchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Database } from '../database.js'
import { HeadState } from './head-state.js'
import { InherentProvider } from './inherent/index.js'
import { OffchainWorker } from '../offchain.js'
import { RuntimeVersion, releaseWorker } from '../wasm-executor/index.js'
import { RuntimeVersion } from '../wasm-executor/index.js'
import { StorageValue } from './storage-layer.js'
import { compactHex } from '../utils/index.js'
import { defaultLogger } from '../logger.js'
Expand Down Expand Up @@ -536,10 +536,9 @@ export class Blockchain {
}

/**
* Close the db and release worker.
* Close the db and disconnect api.
*/
async close() {
await releaseWorker()
await this.api.disconnect()
await this.db?.close()
}
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/wasm-executor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,10 @@ export const getAuraSlotDuration = _.memoize(async (wasm: HexString): Promise<nu
return u8aToBn(hexToU8a(result.Call.result).subarray(0, 8 /* u64: 8 bytes */)).toNumber()
})

export const releaseWorker = async () => {
export const destroyWorker = async () => {
if (!__executor_worker) return
const executor = await __executor_worker
executor.remote[Comlink.releaseProxy]()
// this delay seems to fix hanging tests
// https://github.com/vitest-dev/vitest/issues/3077
await new Promise((resolve) => setTimeout(resolve, 50))
await executor.terminate()
__executor_worker = undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks-db",
"version": "0.9.3-1",
"version": "0.9.3-2",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"@acala-network/chopsticks-testing": "workspace:*",
"@polkadot/api": "^10.10.1",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
"vitest": "^1.0.0-beta.5"
}
}
2 changes: 1 addition & 1 deletion packages/e2e/src/__snapshots__/decoder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ exports[`decoder > with acala > decode key-value 4`] = `
"tokens": {
"accounts": {
"25fqepuLngYL2DK9ApTejNzqPadUUZ9ALYyKWX2jyvEiuZLa": {
"{\\"token\\":\\"ACA\\"}": {
"{"token":"ACA"}": {
"free": "10,000,000,000",
"frozen": "0",
"reserved": "0",
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/src/build-block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const KUSAMA_STORAGE = {

describe.runIf(process.env.CI).each([
{ chain: 'Polkadot', endpoint: 'https://rpc.polkadot.io' },
{ chain: 'Statemint', endpoint: 'wss://statemint-rpc.polkadot.io' },
{ chain: 'Statemint', endpoint: 'wss://statemint-rpc.dwellir.com' },
{ chain: 'Polkadot Collectives', endpoint: 'wss://polkadot-collectives-rpc.polkadot.io' },
{ chain: 'Acala', endpoint: 'wss://acala-rpc-1.aca-api.network' },

{ chain: 'Kusama', endpoint: 'wss://kusama-rpc.polkadot.io', storage: KUSAMA_STORAGE },
{ chain: 'Statemine', endpoint: 'wss://statemine-rpc.polkadot.io' },
{ chain: 'Statemine', endpoint: 'wss://statemine-rpc.dwellir.com' },
{ chain: 'Karura', endpoint: 'wss://karura-rpc-3.aca-api.network' },

{ chain: 'Westend', endpoint: 'wss://westend-rpc.polkadot.io' },
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/src/hrmp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const acalaHRMP: Record<number, HorizontalMessage[]> = {

describe('HRMP', () => {
it('Statemine handles horizonal messages', async () => {
const statemine = await setupContext({ endpoint: 'wss://statemine-rpc.polkadot.io' })
const statemine = await setupContext({ endpoint: 'wss://statemine-rpc.dwellir.com' })
await statemine.chain.newBlock({ horizontalMessages: statemineHRMP })
await matchSystemEvents(statemine, 'xcmpQueue', 'Success')
await statemine.teardown()
Expand All @@ -37,7 +37,7 @@ describe('HRMP', () => {
})

it('Statemine handles horizonal messages block#5,800,000', async () => {
const statemine = await setupContext({ endpoint: 'wss://statemine-rpc.polkadot.io', blockNumber: 5_800_000 })
const statemine = await setupContext({ endpoint: 'wss://statemine-rpc.dwellir.com', blockNumber: 5_800_000 })
await statemine.chain.newBlock({ horizontalMessages: statemineHRMP })
await matchSystemEvents(statemine, 'xcmpQueue', 'Success')
await statemine.teardown()
Expand Down
8 changes: 4 additions & 4 deletions packages/e2e/src/import-storage/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { api, chain, setupApi } from '../helper.js'
import { overrideStorage, overrideWasm } from '@acala-network/chopsticks/utils/override.js'

setupApi({
endpoint: 'wss://acala-rpc-1.aca-api.network',
endpoint: 'wss://acala-rpc.aca-api.network',
blockHash: '0x663c25dc86521f4b7f74dcbc26224bb0fac40e316e6b0bcf6a51de373f37afac', // 2_000_000
})

Expand Down Expand Up @@ -34,14 +34,14 @@ describe('import-storage', () => {
})

it('wasm override works', async () => {
expect(await chain.head.runtimeVersion).toContain({ specVersion: 2096 })
expect(await chain.head.runtimeVersion).toEqual(expect.objectContaining({ specVersion: 2096 }))
const oldWasm = await chain.head.wasm
await overrideWasm(chain, path.join(__dirname, '../../blobs/acala-runtime-2101.txt'))
expect(await chain.head.wasm).not.eq(oldWasm)
expect(await chain.head.runtimeVersion).toContain({ specVersion: 2101 })
expect(await chain.head.runtimeVersion).toEqual(expect.objectContaining({ specVersion: 2101 }))
const blockNumber = chain.head.number
// can produce blocks
await expect(chain.newBlock()).resolves.toContain({ number: blockNumber + 1 })
await expect(chain.newBlock()).resolves.toEqual(expect.objectContaining({ number: blockNumber + 1 }))
})

it('able to reset storage map', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/src/upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe('upgrade', async () => {

const runtime = readFileSync(path.join(__dirname, '../blobs/acala-runtime-2101.txt')).toString().trim()

expect(await chain.head.runtimeVersion).toContain({ specVersion: 2096 })
expect(await chain.head.runtimeVersion).toEqual(expect.objectContaining({ specVersion: 2096 }))
await api.tx.sudo.sudoUncheckedWeight(api.tx.system.setCode(runtime), '0').signAndSend(alice)
await dev.newBlock({ count: 3 })
expect(await chain.head.runtimeVersion).toContain({ specVersion: 2101 })
expect(await chain.head.runtimeVersion).toEqual(expect.objectContaining({ specVersion: 2101 }))
expect(api.runtimeVersion.specVersion).toMatchInlineSnapshot(`2101`)

await api.tx.balances.transfer(bob.address, 1e12).signAndSend(alice)
Expand Down
3 changes: 2 additions & 1 deletion packages/node-test/index.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { setupWithServer } = require('@acala-network/chopsticks')
const { setupWithServer, destroyWorker } = require('@acala-network/chopsticks')

async function main() {
const server = await setupWithServer({ endpoint: 'wss://rpc.polkadot.io', db: 'db.sqlite' })
await server.chain.newBlock()
await server.close()
await destroyWorker()
}
main()
3 changes: 2 additions & 1 deletion packages/node-test/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setupWithServer } from '@acala-network/chopsticks'
import { setupWithServer, destroyWorker } from '@acala-network/chopsticks'

const server = await setupWithServer({ endpoint: 'wss://rpc.polkadot.io', db: 'db.sqlite' })
await server.chain.newBlock()
await server.close()
await destroyWorker()
4 changes: 2 additions & 2 deletions packages/testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks-testing",
"version": "0.9.3-1",
"version": "0.9.3-2",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"type": "module",
Expand All @@ -17,7 +17,7 @@
"@polkadot/types": "^10.10.1"
},
"peerDependencies": {
"vitest": "^0.34.0"
"vitest": "*"
},
"devDependencies": {
"@swc/cli": "0.1.63",
Expand Down
20 changes: 18 additions & 2 deletions packages/testing/src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type RedactOptions = {
hash?: boolean // 32 byte hex
hex?: boolean // any hex with 0x prefix
address?: boolean // base58 address
redactKeys?: RegExp // redact value for keys matching regex
removeKeys?: RegExp // filter out keys matching regex
}

export class Checker {
Expand Down Expand Up @@ -140,7 +142,21 @@ export class Checker {
return obj
}
if (typeof obj === 'object') {
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, process(v)]))
return Object.fromEntries(
Object.entries(obj)
.filter(([k]) => {
if (this.#redactOptions?.removeKeys?.test(k)) {
return false
}
return true
})
.map(([k, v]) => {
if (this.#redactOptions?.redactKeys?.test(k)) {
return [k, '(redacted)']
}
return [k, process(v)]
}),
)
}
return obj
}
Expand Down Expand Up @@ -216,7 +232,7 @@ export const checkUmp = ({ api }: Api) =>
export const checkHrmp = ({ api }: Api) =>
check(api.query.parachainSystem.hrmpOutboundMessages(), 'hrmp').map((value) =>
(value as any[]).map(({ recipient, data }) => ({
data: api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data),
data: api.createType('(XcmpMessageFormat, XcmVersionedXcm)', data).toJSON(),
recipient,
})),
)
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acala-network/chopsticks-utils",
"version": "0.9.3-1",
"version": "0.9.3-2",
"author": "Acala Developers <hello@acala.network>",
"license": "Apache-2.0",
"type": "module",
Expand Down
8 changes: 5 additions & 3 deletions packages/web-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"stream-browserify": "^3.0.0",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vite-tsconfig-paths": "^4.2.1"
"typescript": "^5.2.2"
},
"peerDependencies": {
"vite": "*",
"vite-tsconfig-paths": "*"
}
}
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"noUnusedParameters": true,
"noImplicitAny": false,
"target": "esnext",
"skipLibCheck": false,
"skipLibCheck": true,
"strict": true,
"declaration": true,
"resolveJsonModule": true,
Expand Down
7 changes: 3 additions & 4 deletions vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
test: {
minThreads: process.env.CI ? 1 : undefined /* use defaults */,
maxThreads: process.env.CI ? 4 : undefined /* use defaults */,
hookTimeout: 30000,
testTimeout: 120000,
hookTimeout: 30_000,
testTimeout: 120_000,
include: ['packages/**/*.test.ts'],
bail: process.env.CI ? 1 : undefined /* use defaults */,
pool: 'forks',
},
plugins: [swc.vite(), tsconfigPaths()],
})
Loading

0 comments on commit b724995

Please sign in to comment.