Skip to content

Commit

Permalink
Merge pull request #54 from holochain/emit-signal
Browse files Browse the repository at this point in the history
signal handling
  • Loading branch information
zippy authored Dec 21, 2020
2 parents f4cee02 + e72b16a commit 0319fb2
Show file tree
Hide file tree
Showing 27 changed files with 137 additions and 73 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
matrix:
os: [
ubuntu-latest,
macos-latest
# macos-latest
]
# node: [ '10', '12', '14' ]
node: [ '14' ]
Expand All @@ -22,7 +22,7 @@ jobs:
with:
# borrowed from
# https://github.com/holochain/holochain/blob/6b47b136bc419be6e85000a08a59f67b4c46226c/docs/core_testing.md#requirements
toolchain: stable-2020-08-03
toolchain: stable #-2020-12-18
target: wasm32-unknown-unknown
default: true
# todo: this install holochain step can be removed/simplified
Expand Down
38 changes: 19 additions & 19 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"test/e2e/fixture/zomes/link"
"test/e2e/fixture/zomes/test"
]

[profile.dev]
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ An end-to-end/scenario testing framework for Holochain applications, written in

Tryorama allows you to write test suites about the behavior of multiple Holochain nodes which are networked together, while ensuring that test nodes in different tests do not accidentally join a network together.

Note: this version of tryorama is tested against holochain rev cf4e72416e5afbf29b86d66a3d47ab2f9f6a65d2. Please see [testing Readme](test/README.md) for details on how to run tryorama's own tests.
Note: this version of tryorama is tested against holochain rev 60a906212c17ee067b31511e6b2957746d86297b. Please see [testing Readme](test/README.md) for details on how to run tryorama's own tests.

```bash
npm install @holochain/tryorama
Expand Down Expand Up @@ -120,6 +120,22 @@ const report = await orchestrator.run()
console.log(report)
```

### Signals:
You can add signal handling to your tryorama tests by calling `setSignalHandler` on a player. Here is an example from tryorama's own test suite with a zome that emits a signal with value it's called:

``` javascript
orchestrator.registerScenario('loopback signal zome call', async (s: ScenarioApi) => {
const sentPayload = {value: "foo"};
const [alice] = await s.players([conductorConfig])
alice.setSignalHandler((signal) => {
console.log("Received Signal:",signal)
t.deepEqual(signal.data.payload, sentPayload)
})
const [[alice_happ]] = await alice.installAgentsHapps(installApps)
await alice_happ.cells[0].call('test', 'signal_loopback', sentPayload);
})
```

### Networking and tests:

By default tryorama assumes un-bootstrapped `Quic` networking.
Expand Down
2 changes: 1 addition & 1 deletion ci_scripts/install-holochain.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

REV=cf4e72416e5afbf29b86d66a3d47ab2f9f6a65d2
REV=60a906212c17ee067b31511e6b2957746d86297b

cargo install --force holochain \
--git https://github.com/holochain/holochain.git \
Expand Down
6 changes: 3 additions & 3 deletions ci_scripts/run-test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
echo `pwd`
cd test/e2e/fixture/zomes/link
cd test/e2e/fixture/zomes/test
cargo build --release --target wasm32-unknown-unknown --target-dir ./target
cp target/wasm32-unknown-unknown/release/test_wasm_link.wasm ../../../link.dna.workdir
cp target/wasm32-unknown-unknown/release/test_wasm.wasm ../../../test.dna.workdir/test.wasm
cd ../../..
dna-util -c link.dna.workdir
dna-util -c test.dna.workdir
cd ../..
npm install
npm run test
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "https://github.com/holochain/tryorama"
},
"version": "0.4.0-dev.2",
"version": "0.4.0-dev.3",
"description": "test framework for holochain hApps",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
25 changes: 13 additions & 12 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,22 @@ export class ScenarioApi {
_createLocalPlayerBuilder = async (playerName: string, configSeed: T.ConfigSeed): Promise<PlayerBuilder> => {
return async () => {
const partialConfigSeedArgs = await localConfigSeedArgs()
const configJson = this._generateConfigFromSeed(partialConfigSeedArgs, playerName, configSeed)
const configYaml = this._generateConfigFromSeed(partialConfigSeedArgs, playerName, configSeed)
const { adminInterfacePort, configDir } = partialConfigSeedArgs
await fs.writeFile(getConfigPath(configDir), YAML.stringify(configJson))
await fs.writeFile(getConfigPath(configDir), YAML.stringify(configYaml))

logger.debug('api.players: player config committed for %s', playerName)
return new Player({
scenarioUUID: this._uuid,
name: playerName,
config: configJson,
configDir,
adminInterfacePort,
spawnConductor: spawnLocal,
onJoin: () => console.log("FIXME: ignoring onJoin"),//instances.forEach(instance => this._waiter.addNode(instance.dna, playerName)),
onLeave: () => console.log("FIXME: ignoring onLeave"),//instances.forEach(instance => this._waiter.removeNode(instance.dna, playerName)),
onActivity: () => this._restartTimer(),
onSignal: (signal_data) => {},
scenarioUUID: this._uuid,
name: playerName,
config: configYaml,
configDir,
adminInterfacePort,
spawnConductor: spawnLocal,
onJoin: () => console.log("FIXME: ignoring onJoin"),//instances.forEach(instance => this._waiter.addNode(instance.dna, playerName)),
onLeave: () => console.log("FIXME: ignoring onLeave"),//instances.forEach(instance => this._waiter.removeNode(instance.dna, playerName)),
onActivity: () => this._restartTimer(),
onSignal: (signal) => {console.info("got signal, doing nothing with it: %o", signal)},
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type CallAdminFunc = (method: string, params: Record<string, any>) => Pro
export class Conductor {

name: string
onSignal: ({ instanceId: string, signal: Signal }) => void
onSignal: (Signal) => void
logger: any
kill: KillFn
adminClient: AdminWebsocket | null
Expand Down Expand Up @@ -120,8 +120,8 @@ export class Conductor {
const { port: appInterfacePort } = await this.adminClient.attachAppInterface({ port: 0 })
const appWsUrl = `ws://${this._machineHost}:${appInterfacePort}`
this.appClient = await AppWebsocket.connect(appWsUrl, (signal) => {
this._onActivity()
console.info("got signal, doing nothing with it: %o", signal)
this._onActivity();
this.onSignal(signal);
})
this.logger.debug(`connectInterfaces :: connected app interface at ${appWsUrl}`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const spawnLocal: T.SpawnConductorFn = async (player: Player, { handleHoo
handle.kill(...args)
return killPromise
},
onSignal: player.onSignal.bind(player),
onSignal: player.onSignal,//player.onSignal.bind(player),
onActivity: player.onActivity,
machineHost: `localhost`,
adminPort: player._adminInterfacePort,
Expand Down
11 changes: 9 additions & 2 deletions src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ConstructorArgs = {
config: RawConductorConfig,
configDir: string,
adminInterfacePort: number,
onSignal: ({ instanceId: string, signal: Signal }) => void,
onSignal: (Signal) => void,
onJoin: () => void,
onLeave: () => void,
onActivity: () => void,
Expand All @@ -39,7 +39,7 @@ export class Player {
config: RawConductorConfig
onJoin: () => void
onLeave: () => void
onSignal: ({ instanceId: string, signal: Signal }) => void
onSignal: (Signal) => void
onActivity: () => void
scenarioUUID: string

Expand Down Expand Up @@ -158,6 +158,13 @@ export class Player {
return this._conductor!._installHapp(happ)
}

setSignalHandler = (handler) => {
this.onSignal = handler
if (this._conductor) {
this._conductor.onSignal = handler
}
}

_conductorGuard = (context) => {
if (this._conductor === null) {
const msg = `Attempted conductor action when no conductor is running! You must \`.startup()\` first.\nAction: ${context}`
Expand Down
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ When updating tryorama against a new version of holochain please replace the old

```
./README.md
test/e2e/fixture/zomes/link/Cargo.toml
test/e2e/fixture/zomes/test/Cargo.toml
ci_scripts/install-holochain.sh
```

Expand Down
File renamed without changes.

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

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "test_wasm_link"
name = "test_wasm"
version = "0.0.1"
authors = [ "thedavidmeister", "thedavidmeister@gmail.com" ]
edition = "2018"

[lib]
name = "test_wasm_link"
name = "test_wasm"
crate-type = [ "cdylib", "rlib" ]

[dependencies]
hdk3 = { git = "https://github.com/holochain/holochain", rev = "cf4e72416e5afbf29b86d66a3d47ab2f9f6a65d2", package = "hdk3" }
hdk3 = { git = "https://github.com/holochain/holochain", rev = "60a906212c17ee067b31511e6b2957746d86297b", package = "hdk3" }
serde = "1.0.104"
test_wasm_common = { git = "https://github.com/holochain/holochain", rev = "cf4e72416e5afbf29b86d66a3d47ab2f9f6a65d2", package = "test_wasm_common" }
test_wasm_common = { git = "https://github.com/holochain/holochain", rev = "60a906212c17ee067b31511e6b2957746d86297b", package = "test_wasm_common" }
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ fn delete_all_links(_: ()) -> ExternResult<()> {
}
Ok(())
}

#[derive(Serialize, Deserialize, SerializedBytes, Debug)]
pub struct LoopBack {
value: String,
}

#[hdk_extern]
fn signal_loopback(value: LoopBack) -> ExternResult<()> {
emit_signal(&value)?;
Ok(())
}
3 changes: 2 additions & 1 deletion test/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ process.on('unhandledRejection', error => {
console.error('****************************');
});

const dnaLocationLocal = path.join(__dirname, 'link.dna.gz')
const dnaLocationLocal = path.join(__dirname, 'test.dna.gz')

const localOrchestrator = (extra = {}) => new Orchestrator({
middleware: compose(runSeries(), localOnly),
Expand All @@ -21,3 +21,4 @@ const localOrchestrator = (extra = {}) => new Orchestrator({
require('./test-always-on')(localOrchestrator, () => testConfig(dnaLocationLocal))
// require('./test-always-on')(singleConductorOrchestrator, () => testConfig(dnaLocationLocal))
require('./test-dynamic-on')(localOrchestrator, () => testConfig(dnaLocationLocal))
require('./test-signal')(localOrchestrator, () => testConfig(dnaLocationLocal))
Binary file removed test/e2e/link.dna.gz
Binary file not shown.
10 changes: 0 additions & 10 deletions test/e2e/link.dna.workdir/dna.json

This file was deleted.

Binary file removed test/e2e/link.dna.workdir/test_wasm_link.wasm
Binary file not shown.
Loading

0 comments on commit 0319fb2

Please sign in to comment.