Skip to content

Commit

Permalink
refactor: move benchmarkerator and test support code into their own p…
Browse files Browse the repository at this point in the history
…ackages
  • Loading branch information
FUDCo committed Nov 18, 2023
1 parent 0f42fb6 commit 699d9e1
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ jobs:
- name: yarn test (assert)
if: (success() || failure())
run: cd packages/assert && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
- name: yarn test (benchmark)
if: (success() || failure())
run: cd packages/benchmark && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
- name: yarn test (deployment)
if: (success() || failure())
run: cd packages/deployment && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
Expand Down Expand Up @@ -157,6 +160,9 @@ jobs:
- name: yarn test (swing-store)
if: (success() || failure())
run: cd packages/swing-store && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
- name: yarn test (test-support)
if: (success() || failure())
run: cd packages/test-support && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
- name: yarn test (cosmic-proto)
if: (success() || failure())
run: cd packages/cosmic-proto && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT
Expand Down
2 changes: 2 additions & 0 deletions packages/agoric-cli/src/sdk-package-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default [
"@agoric/access-token",
"@agoric/assert",
"@agoric/base-zone",
"@agoric/benchmark",
"@agoric/boot",
"@agoric/builders",
"@agoric/cache",
Expand Down Expand Up @@ -37,6 +38,7 @@ export default [
"@agoric/swingset-vat",
"@agoric/swingset-xsnap-supervisor",
"@agoric/telemetry",
"@agoric/test-support",
"@agoric/time",
"@agoric/vat-data",
"@agoric/vats",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,11 @@ yourself).[^2]
Those will themselves be deprecated and/or moved into `benchmarks`.
However, as of this writing that has not yet been done.

The first thing a benchmark should do is import The Benchmarkerator:[^3]
The first thing a benchmark should do is import The Benchmarkerator:
```
import { bench } from '@agoric/benchmark';
```

[^3]: As of this writing The Benchmarkerator actually lives in
`@agoric/boot/test/boostrapTests/benchmarkerator.js`. This should be
changed soon, hopefully before the first PR containing this writeup is
landed, in which case you will never see this footnote.

Note that this importation usually should be the very first thing you do, much
as you typically import `@agoric/swingset-vat/tools/prepare-test-env-ava.js` or
`@agoric/zoe/tools/prepare-test-env-ava.js` or the like as the first thing in a
Expand Down
66 changes: 66 additions & 0 deletions packages/benchmark/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "@agoric/benchmark",
"version": "0.1.0",
"private": true,
"description": "Benchmark support",
"type": "module",
"main": "./src/benchmarkerator.js",
"exports": {
".": "./src/benchmarkerator.js"
},
"repository": "https://github.com/Agoric/agoric-sdk",
"scripts": {
"build": "exit 0",
"test": "exit 0",
"test:xs": "exit 0",
"lint-fix": "yarn lint:eslint --fix",
"lint": "run-s --continue-on-error lint:*",
"lint:types": "tsc",
"lint:eslint": "eslint ."
},
"keywords": [],
"author": "Agoric",
"license": "Apache-2.0",
"dependencies": {
"@agoric/assert": "^0.6.0",
"@agoric/cosmic-swingset": "^0.41.3",
"@agoric/internal": "^0.3.2",
"@agoric/inter-protocol": "^0.16.1",
"@agoric/test-support": "^0.1.0",
"@agoric/vats": "^0.15.1",
"@agoric/zoe": "^0.26.2",
"@endo/init": "^0.5.59"
},
"devDependencies": {},
"files": [
"CHANGELOG.md",
"src/",
"scripts/",
"tools/",
"*.json",
"globals.d.ts",
"exported.js"
],
"engines": {
"node": ">=14.15.0"
},
"ava": {
"extensions": {
"js": true,
"ts": "module"
},
"files": [
"test/**/test-*.js",
"test/**/test-*.ts"
],
"nodeArguments": [
"--loader=tsx",
"--no-warnings"
],
"require": [
"@endo/init/debug.js"
],
"timeout": "20m",
"workerThreads": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import fs from 'node:fs';
import '@endo/init/pre-bundle-source.js';
import '@endo/init';

// XXX The following four imports are present only to make `tsc` shut up. They do no actual work.
import '@agoric/vats/exported.js';
import '@agoric/inter-protocol/exported.js';
import '@agoric/zoe/exported.js';
import '@agoric/cosmic-swingset/src/launch-chain.js';

import { Fail } from '@agoric/assert';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js';
import { makeSwingsetTestKit } from './supports.ts';
import { makeWalletFactoryDriver } from './drivers.ts';
import {
makeSwingsetTestKit,
makeWalletFactoryDriver,
} from '@agoric/test-support';

// When I was a child my family took a lot of roadtrips around California to go
// camping and backpacking and so on. It was not uncommon in those days (nor is
Expand Down Expand Up @@ -38,7 +46,7 @@ import { makeWalletFactoryDriver } from './drivers.ts';
* @typedef {{
* options: Record<string, string>,
* argv: string[],
* actors: Record<string, import('./drivers.js').SmartWalletDriver>,
* actors: Record<string, import('@agoric/test-support').SmartWalletDriver>,
* title?: string,
* rounds?: number,
* config?: Record<string, unknown>,
Expand Down Expand Up @@ -586,4 +594,5 @@ export const makeBenchmarkerator = async () => {
/**
* The normal singleton benchmarkerator.
*/
// eslint-disable-next-line @jessie.js/safe-await-separator
export const bench = await makeBenchmarkerator();
17 changes: 17 additions & 0 deletions packages/benchmark/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"checkJs": true,
"maxNodeModuleJsDepth": 2,
},
"include": [
"*.js",
"scripts/**/*.js",
"src/**/*.js",
"test/**/*.js",
"test/**/*.ts",
"tools/**/*.js",
],
}
2 changes: 2 additions & 0 deletions packages/boot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"devDependencies": {
"@agoric/assert": "^0.6.0",
"@agoric/benchmark": "^0.1.0",
"@agoric/cosmic-swingset": "^0.41.3",
"@agoric/deploy-script-support": "^0.10.3",
"@agoric/governance": "^0.10.3",
Expand All @@ -47,6 +48,7 @@
"@agoric/swing-store": "^0.9.1",
"@agoric/swingset-liveslots": "^0.10.2",
"@agoric/swingset-vat": "^0.32.2",
"@agoric/test-support": "^0.1.0",
"@agoric/time": "^0.3.2",
"ava": "^5.3.0",
"c8": "^7.13.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/boot/test/bootstrapTests/bench-vaults-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import engineGC from '@agoric/internal/src/lib-nodejs/engine-gc.js';

import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js';
import { makeSwingsetTestKit } from './supports.ts';
import { makeWalletFactoryDriver } from './drivers.ts';
import {
makeSwingsetTestKit,
makeWalletFactoryDriver,
} from '@agoric/test-support';

/**
* @type {import('ava').TestFn<
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/test/bootstrapTests/benchmark-vaults.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bench } from './benchmarkerator.js';
import { bench } from '@agoric/benchmark';

// eslint-disable-next-line import/order
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/boot/test/bootstrapTests/liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
makeGovernanceDriver,
makePriceFeedDriver,
makeWalletFactoryDriver,
} from './drivers.ts';
import { makeSwingsetTestKit } from './supports.ts';
makeSwingsetTestKit,
} from '@agoric/test-support';

export type LiquidationSetup = {
vaults: {
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/test/bootstrapTests/test-demo-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { PowerFlags } from '@agoric/vats/src/walletFlags.js';

import type { TestFn } from 'ava';
import { makeSwingsetTestKit, keyArrayEqual } from './supports.ts';
import { makeSwingsetTestKit, keyArrayEqual } from '@agoric/test-support';

const { keys } = Object;

Expand Down
7 changes: 5 additions & 2 deletions packages/boot/test/bootstrapTests/test-vats-restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-
import { TestFn } from 'ava';
import { BridgeHandler } from '@agoric/vats';
import type { EconomyBootstrapSpace } from '@agoric/inter-protocol/src/proposals/econ-behaviors.js';
import { makeProposalExtractor, makeSwingsetTestKit } from './supports.ts';
import { makeWalletFactoryDriver } from './drivers.ts';
import {
makeProposalExtractor,
makeSwingsetTestKit,
makeWalletFactoryDriver,
} from '@agoric/test-support';

const { Fail } = assert;

Expand Down
6 changes: 4 additions & 2 deletions packages/boot/test/bootstrapTests/test-vaults-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
} from '@agoric/vats/tools/board-utils.js';
import type { TestFn } from 'ava';
import { ParamChangesOfferArgs } from '@agoric/inter-protocol/src/econCommitteeCharter.js';
import { makeWalletFactoryDriver } from './drivers.ts';
import { makeSwingsetTestKit } from './supports.ts';
import {
makeSwingsetTestKit,
makeWalletFactoryDriver,
} from '@agoric/test-support';

// presently all these tests use one collateral manager
const collateralBrandKey = 'ATOM';
Expand Down
6 changes: 4 additions & 2 deletions packages/boot/test/bootstrapTests/test-vaults-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-
import { ExecutionContext, TestFn } from 'ava';
import { FakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';
import { EconomyBootstrapSpace } from '@agoric/inter-protocol/src/proposals/econ-behaviors.js';
import { makeWalletFactoryDriver } from './drivers.ts';
import { makeSwingsetTestKit } from './supports.ts';
import {
makeSwingsetTestKit,
makeWalletFactoryDriver,
} from '@agoric/test-support';

// presently all these tests use one collateral manager
const collateralBrandKey = 'ATOM';
Expand Down
9 changes: 6 additions & 3 deletions packages/boot/test/bootstrapTests/test-zcf-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import path from 'path';
import { BridgeHandler } from '@agoric/vats';
import { makeAgoricNamesRemotesFromFakeStorage } from '@agoric/vats/tools/board-utils.js';
import { TestFn } from 'ava';
import { makeZoeDriver } from './drivers.ts';
import { matchAmount } from './supports.js';
import { makeProposalExtractor, makeSwingsetTestKit } from './supports.ts';
import {
matchAmount,
makeZoeDriver,
makeProposalExtractor,
makeSwingsetTestKit,
} from '@agoric/test-support';

const filename = new URL(import.meta.url).pathname;
const dirname = path.dirname(filename);
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/test/upgrading/test-upgrade-vats.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
matchAmount,
matchIter,
matchRef,
} from '../bootstrapTests/supports.ts';
} from '@agoric/test-support';

/**
* @type {import('ava').TestFn<{}>}
Expand Down
51 changes: 51 additions & 0 deletions packages/test-support/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@agoric/test-support",
"version": "0.1.0",
"description": "Support libraries for testing on chain",
"type": "module",
"main": "./src/index.js",
"exports": {
".": "./src/index.js"
},
"repository": "https://github.com/Agoric/agoric-sdk",
"author": "Agoric",
"license": "Apache-2.0",
"scripts": {
"build": "exit 0",
"test": "exit 0",
"test:xs": "exit 0",
"lint-fix": "yarn lint:eslint --fix",
"lint": "run-s --continue-on-error lint:*",
"lint:types": "tsc",
"lint:eslint": "eslint ."
},
"dependencies": {
"@endo/eventual-send": "^0.17.5",
"@endo/stream": "^0.3.28",
"@agoric/assert": "^0.6.0",
"@agoric/cosmic-swingset": "^0.41.3",
"@agoric/inter-protocol": "^0.16.1",
"@agoric/internal": "^0.3.2",
"@agoric/kmarshal": "^0.1.0",
"@agoric/smart-wallet": "^0.5.3",
"@agoric/swing-store": "^0.9.1",
"@agoric/swingset-vat": "^0.32.2",
"@agoric/time": "^0.3.2",
"@agoric/vats": "^0.15.1",
"ava": "^5.3.0",
"import-meta-resolve": "^2.2.1"
},
"devDependencies": {},
"publishConfig": {
"access": "public"
},
"ava": {
"files": [
"test/**/test-*.js"
],
"require": [
"@endo/init/debug.js"
],
"timeout": "2m"
}
}
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/test-support/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './supports.ts';
export * from './drivers.ts';
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { initSwingStore } from '@agoric/swing-store';
import { loadSwingsetConfigFile } from '@agoric/swingset-vat';
import { krefOf, kunser } from '@agoric/kmarshal';
import { TimeMath, Timestamp } from '@agoric/time';
import '@agoric/vats/exported.js';
import {
boardSlottingMarshaller,
slotToBoardRemote,
Expand Down Expand Up @@ -213,7 +214,7 @@ interface Powers {

export const makeProposalExtractor = ({ childProcess, fs }: Powers) => {
const getPkgPath = (pkg, fileName = '') =>
new URL(`../../../${pkg}/${fileName}`, import.meta.url).pathname;
new URL(`../../${pkg}/${fileName}`, import.meta.url).pathname;

const importSpec = spec =>
importMetaResolve(spec, import.meta.url).then(u => new URL(u).pathname);
Expand Down
14 changes: 14 additions & 0 deletions packages/test-support/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This file can contain .js-specific Typescript compiler config.
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"checkJs": true,
"maxNodeModuleJsDepth": 2,
},
"include": [
"src/**/*.js",
"test/**/*.js"
]
}

0 comments on commit 699d9e1

Please sign in to comment.