Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(release): merge develop #131

Merged
merged 6 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- name: Check out source code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install nix
uses: cachix/install-nix-action@v16
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed
### Fixed

## [0.5.7]

### Added
- Common: optional timeout for zome calls [PR \#130](https://github.com/holochain/tryorama/pull/130)

### Fixed
- Local conductor: log conductor startup only once and at correct moment [PR \#130](https://github.com/holochain/tryorama/pull/130)

## [0.5.6]

### Fixed
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ try {
}
```

### Logging

The log level can be set with the environment variable `TRYORAMA_LOG_LEVEL`.
Log levels used in Tryorama are `debug`, `verbose` and `info`. The default
level is `info`. To set the log level for a test run, prepend the test command
with:

```bash
TRYORAMA_LOG_LEVEL=debug node test.js
```

## Concepts

[Scenarios](./docs/tryorama.scenario.md) provide high-level functions to
Expand Down
4 changes: 2 additions & 2 deletions crates/trycp_server/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 docs/tryorama.callzomefn.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The function for calling a zome from a specific cell.
<b>Signature:</b>

```typescript
export declare type CallZomeFn = <T>(request: CellZomeCallRequest) => Promise<T>;
export declare type CallZomeFn = <T>(request: CellZomeCallRequest, timeout?: number) => Promise<T>;
```
<b>References:</b> [CellZomeCallRequest](./tryorama.cellzomecallrequest.md)

4 changes: 2 additions & 2 deletions docs/tryorama.getzomecaller.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

## getZomeCaller variable

Get a shorthand function to call a Cell's Zome.
Get a shorthand function to call a cell's zome.

<b>Signature:</b>

```typescript
getZomeCaller: (cell: CallableCell, zomeName: string) => <T>(fnName: string, payload?: unknown) => Promise<T>
getZomeCaller: (cell: CallableCell, zomeName: string) => <T>(fnName: string, payload?: unknown, timeout?: number) => Promise<T>
```
2 changes: 1 addition & 1 deletion docs/tryorama.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ TryCP stands for Tryorama Control Protocol (TryCP) and is a protocol to enable r
| [createConductor](./tryorama.createconductor.md) | The function to create a conductor. It starts a sandbox conductor via the Holochain CLI. |
| [createTryCpConductor](./tryorama.createtrycpconductor.md) | The function to create a TryCP Conductor (aka "Player"). |
| [DEFAULT\_PARTIAL\_PLAYER\_CONFIG](./tryorama.default_partial_player_config.md) | The default partial config for a TryCP conductor. |
| [getZomeCaller](./tryorama.getzomecaller.md) | Get a shorthand function to call a Cell's Zome. |
| [getZomeCaller](./tryorama.getzomecaller.md) | Get a shorthand function to call a cell's zome. |
| [pause](./tryorama.pause.md) | A utility function to wait the given amount of time. |
| [runScenario](./tryorama.runscenario.md) | A wrapper function to create and run a scenario. A scenario is created and all involved conductors are shut down and cleaned up after running. |
| [TRYCP\_SUCCESS\_RESPONSE](./tryorama.trycp_success_response.md) | Empty success response. |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@holochain/tryorama",
"description": "Toolset to manage Holochain conductors and facilitate running test scenarios",
"version": "0.5.6",
"version": "0.5.7",
"author": "Holochain Foundation",
"keywords": [
"holochain",
Expand Down
38 changes: 22 additions & 16 deletions ts/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,39 @@ const getCallableCell = (
agentPubKey: AgentPubKey
) => ({
...cell,
callZome: async <T>(request: CellZomeCallRequest) => {
const callZomeResponse = await conductor.appWs().callZome({
...request,
cap_secret: request.cap_secret ?? null,
cell_id: cell.cell_id,
provenance: request.provenance || agentPubKey,
payload: request.payload ?? null,
});
callZome: async <T>(request: CellZomeCallRequest, timeout?: number) => {
const callZomeResponse = await conductor.appWs().callZome(
{
...request,
cap_secret: request.cap_secret ?? null,
cell_id: cell.cell_id,
provenance: request.provenance || agentPubKey,
payload: request.payload ?? null,
},
timeout
);
assertZomeResponse<T>(callZomeResponse);
return callZomeResponse;
},
});

/**
* Get a shorthand function to call a Cell's Zome.
* Get a shorthand function to call a cell's zome.
*
* @param cell - The Cell to call the Zome on.
* @param cell - The cell to call the zome on.
* @param zomeName - The name of the Zome to call.
* @returns A function to call the specified Zome.
*
* @public
*/
export const getZomeCaller =
(cell: CallableCell, zomeName: string) =>
<T>(fnName: string, payload?: unknown): Promise<T> =>
cell.callZome<T>({
zome_name: zomeName,
fn_name: fnName,
payload,
});
<T>(fnName: string, payload?: unknown, timeout?: number): Promise<T> =>
cell.callZome<T>(
{
zome_name: zomeName,
fn_name: fnName,
payload,
},
timeout
);
4 changes: 1 addition & 3 deletions ts/src/local/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,12 @@ export class Conductor implements IConductor {
);
const startPromise = new Promise<void>((resolve) => {
runConductorProcess.stdout.on("data", (data: Buffer) => {
logger.debug(`starting conductor\n${data}`);

const numberMatches = data
.toString()
.match(/Running conductor on admin port (\d+)/);
if (numberMatches) {
this.adminApiUrl.port = numberMatches[1];
logger.debug(`admin port ${this.adminApiUrl.port}\n`);
logger.debug(`starting conductor\n${data}`);
}

if (
Expand Down
5 changes: 4 additions & 1 deletion ts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export type CellZomeCallRequest = Omit<
*
* @public
*/
export type CallZomeFn = <T>(request: CellZomeCallRequest) => Promise<T>;
export type CallZomeFn = <T>(
request: CellZomeCallRequest,
timeout?: number
) => Promise<T>;

/**
* Extends an installed cell by a function to call a zome.
Expand Down
17 changes: 16 additions & 1 deletion ts/test/local/conductor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { HeaderHash } from "@holochain/client";
import {
AppSignal,
AppSignalCb,
DnaSource,
EntryHash,
HeaderHash,
} from "@holochain/client";
import assert from "node:assert";
import { readFileSync } from "node:fs";
import { URL } from "node:url";
import test from "tape-promise/tape.js";
Expand Down Expand Up @@ -253,6 +254,20 @@ test("Local Conductor - Install hApp bundle and access cells with role ids", asy
await cleanAllConductors();
});

test("Local Conductor - Zome call can time out before completion", async (t) => {
const conductor = await createConductor();
const aliceHapp = await conductor.installHappBundle({
path: FIXTURE_HAPP_URL.pathname,
});
const cell = aliceHapp.namedCells.get("test");
assert(cell);

await t.rejects(cell.callZome({ fn_name: "create", zome_name: "crud" }, 1));

await conductor.shutDown();
await cleanAllConductors();
});

test("Local Conductor - Create and read an entry using the entry zome", async (t) => {
const conductor = await createConductor();

Expand Down