Skip to content
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
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added
- A new method `storageArc` that polls for network metrics and to check if an agent's storage arc is equal to a desired storage arc for a given dna hash. ([#300](https://github.com/holochain/tryorama/pull/301))
- A new configuration field `targetArcFactor` has been added to `NetworkConfig`, allowing test scenarios to be written with 0-arc conductors ([#300](https://github.com/holochain/tryorama/pull/300))
- A new optional field `label` was added to the types `AppWithOptions`, `ConductorOptions`, `CreateConductorOptions`, and to the function `addConductor`. It allows overriding the default label which will prefix log messages of that Conductor instance.

### Removed
### Changed
- Log messages from Conductors that were created with `addPlayers` functions are now prefixed by `Tryorama - Player #` where "#" is the Player index. This makes it easier to distinguish log messages from different conductors. ([#302](https://github.com/holochain/tryorama/pull/302))

### Fixed
- Network options are now applied before the conductor launches, to ensure they actually alter the conductor configuration. ([#300](https://github.com/holochain/tryorama/pull/300))
- When creating conductors with `Scenario#addPlayers`, `Scenario#installAppsForPlayers`, `Scenario#installSameAppForPlayers`, `Scenario#addPlayersWithApps`, and `Scenario#addPlayersWithSameApp` each conductor is created sequentially and waits for startup, with a 1s delay in-between. This is a workaround to avoid connection failures which can cause test failures.
Expand Down
11 changes: 0 additions & 11 deletions docs/tryorama.appwithoptions.label.md

This file was deleted.

19 changes: 0 additions & 19 deletions docs/tryorama.appwithoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,6 @@ AppBundleSource
</td><td>


</td></tr>
<tr><td>

[label?](./tryorama.appwithoptions.label.md)


</td><td>


</td><td>

string


</td><td>

_(Optional)_


</td></tr>
<tr><td>

Expand Down
13 changes: 0 additions & 13 deletions docs/tryorama.conductoroptions.label.md

This file was deleted.

19 changes: 0 additions & 19 deletions docs/tryorama.conductoroptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,6 @@ URL
_(Optional)_ A bootstrap server URL for peers to discover each other.


</td></tr>
<tr><td>

[label?](./tryorama.conductoroptions.label.md)


</td><td>


</td><td>

string


</td><td>

_(Optional)_ Label to identify this conductor in logs.


</td></tr>
<tr><td>

Expand Down
2 changes: 1 addition & 1 deletion docs/tryorama.createconductoroptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Options for using the conductor factory.
**Signature:**

```typescript
export type CreateConductorOptions = Pick<ConductorOptions, "bootstrapServerUrl" | "timeout" | "label">;
export type CreateConductorOptions = Pick<ConductorOptions, "bootstrapServerUrl" | "timeout">;
```
**References:** [ConductorOptions](./tryorama.conductoroptions.md)

18 changes: 1 addition & 17 deletions docs/tryorama.scenario.addconductor.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Create and add a conductor to the scenario.
**Signature:**

```typescript
addConductor(networkConfig?: NetworkConfig, label?: string): Promise<Conductor>;
addConductor(networkConfig?: NetworkConfig): Promise<Conductor>;
```

## Parameters
Expand Down Expand Up @@ -45,22 +45,6 @@ networkConfig
_(Optional)_


</td></tr>
<tr><td>

label


</td><td>

string


</td><td>

_(Optional)_


</td></tr>
</tbody></table>
**Returns:**
Expand Down
2 changes: 1 addition & 1 deletion docs/tryorama.scenario.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Description
</th></tr></thead>
<tbody><tr><td>

[addConductor(networkConfig, label)](./tryorama.scenario.addconductor.md)
[addConductor(networkConfig)](./tryorama.scenario.addconductor.md)


</td><td>
Expand Down
57 changes: 23 additions & 34 deletions ts/src/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import { _ALLOWED_ORIGIN } from "./conductor-helpers.js";
import { makeLogger } from "./logger.js";
import { AppWithOptions } from "./scenario.js";
import { AgentsAppsOptions } from "./types.js";
import { Logger } from "winston";

const defaultLogger = makeLogger();
const logger = makeLogger();

/**
* @public
Expand Down Expand Up @@ -53,11 +52,6 @@ export interface ConductorOptions {
* Timeout for requests to Admin and App API.
*/
timeout?: number;

/**
* Label to identify this conductor in logs.
*/
label?: string;
}

/**
Expand Down Expand Up @@ -168,7 +162,7 @@ interface ConductorConfigYaml {
*/
export type CreateConductorOptions = Pick<
ConductorOptions,
"bootstrapServerUrl" | "timeout" | "label"
"bootstrapServerUrl" | "timeout"
>;

/**
Expand All @@ -186,7 +180,6 @@ export const createConductor = async (
const createConductorOptions: CreateConductorOptions = pick(options, [
"bootstrapServerUrl",
"timeout",
"label",
]);
const conductor = await Conductor.create(
signalingServerUrl,
Expand Down Expand Up @@ -218,16 +211,14 @@ export class Conductor {
private adminApiUrl: URL;
private _adminWs: AdminWebsocket | undefined;
private _appWs: AppWebsocket | undefined;
private _logger: Logger;
private readonly timeout: number;

private constructor(label?: string, timeout?: number) {
private constructor(timeout?: number) {
this.conductorProcess = undefined;
this.conductorDir = undefined;
this.adminApiUrl = new URL(HOST_URL.href);
this._adminWs = undefined;
this._appWs = undefined;
this._logger = makeLogger(label);
this.timeout = timeout ?? DEFAULT_TIMEOUT;
}

Expand All @@ -247,15 +238,15 @@ export class Conductor {
}
args.push("webrtc");
args.push(signalingServerUrl.href);
defaultLogger.debug("spawning hc sandbox with args:", args);
logger.debug("spawning hc sandbox with args:", args);
const createConductorProcess = spawn("hc", args);
createConductorProcess.stdin.write(LAIR_PASSWORD);
createConductorProcess.stdin.end();

const conductor = new Conductor(options?.label, options?.timeout);
const conductor = new Conductor(options?.timeout);
return new Promise<Conductor>((resolve, reject) => {
createConductorProcess.stdout.on("data", (data: Buffer) => {
defaultLogger.debug(`creating conductor config\n${data.toString()}`);
logger.debug(`creating conductor config\n${data.toString()}`);
const tmpDirMatches = [
...data.toString().matchAll(/DataRootPath\("(.*?)"\)/g),
];
Expand All @@ -267,7 +258,7 @@ export class Conductor {
resolve(conductor);
});
createConductorProcess.stderr.on("data", (err) => {
defaultLogger.error(`error when creating conductor config: ${err}\n`);
logger.error(`error when creating conductor config: ${err}\n`);
reject(err);
});
});
Expand Down Expand Up @@ -307,8 +298,8 @@ export class Conductor {
},
};
const yamlDump = yaml.dump(conductorConfigYaml);
this._logger.debug("Updated conductor config:");
this._logger.debug(yamlDump);
logger.debug("Updated conductor config:");
logger.debug(yamlDump);
writeFileSync(`${this.conductorDir}/${CONDUCTOR_CONFIG}`, yamlDump);
}

Expand All @@ -322,9 +313,7 @@ export class Conductor {
"error starting conductor: conductor has not been created",
);
if (this.conductorProcess) {
this._logger.error(
"error starting conductor: conductor is already running\n",
);
logger.error("error starting conductor: conductor is already running\n");
return;
}

Expand All @@ -341,21 +330,21 @@ export class Conductor {
let adminPortLogged = false;
const adminPortPromise = new Promise<string>((resolve) => {
runConductorProcess.stdout.on("data", (data: Buffer) => {
this._logger.info(data.toString());
logger.info(data.toString());

if (!adminPortLogged) {
if(!adminPortLogged) {
// Once we have an admin port, the conductor is launched and usable.
const adminPort = data.toString().match(/###ADMIN_PORT:(\d*)###/);

if (adminPort !== null) {
if(adminPort !== null) {
adminPortLogged = true;
resolve(adminPort[1]);
}
}
});

runConductorProcess.stderr.on("data", (data: Buffer) => {
this._logger.error(data.toString());
logger.error(data.toString());
});
});
this.adminApiUrl.port = await adminPortPromise;
Expand All @@ -369,11 +358,11 @@ export class Conductor {
*/
async shutDown() {
if (!this.conductorProcess) {
this._logger.info("shut down conductor: conductor is not running");
logger.info("shut down conductor: conductor is not running");
return null;
}

this._logger.debug("closing admin and app web sockets\n");
logger.debug("closing admin and app web sockets\n");
if (this._adminWs) {
await this._adminWs.client.close();
this._adminWs = undefined;
Expand All @@ -383,7 +372,7 @@ export class Conductor {
this._appWs = undefined;
}

this._logger.debug("shutting down conductor\n");
logger.debug("shutting down conductor\n");
return new Promise<number | null>((resolve) => {
assert(this.conductorProcess);
// Kill process after timeout if terminating didn't succeed.
Expand All @@ -408,7 +397,7 @@ export class Conductor {
wsClientOptions: { origin: _ALLOWED_ORIGIN },
defaultTimeout: this.timeout,
});
this._logger.debug(`connected to Admin API @ ${this.adminApiUrl.href}\n`);
logger.debug(`connected to Admin API @ ${this.adminApiUrl.href}\n`);
}

/**
Expand All @@ -422,7 +411,7 @@ export class Conductor {
port: await getPort({ port: portNumbers(30000, 40000) }),
allowed_origins: _ALLOWED_ORIGIN,
};
this._logger.debug(`attaching App API to port ${request.port}\n`);
logger.debug(`attaching App API to port ${request.port}\n`);
const { port } = await this.adminWs().attachAppInterface(request);
return port;
}
Expand All @@ -435,7 +424,7 @@ export class Conductor {
* @returns An app websocket.
*/
async connectAppWs(token: AppAuthenticationToken, port: number) {
this._logger.debug(`connecting App WebSocket to port ${port}\n`);
logger.debug(`connecting App WebSocket to port ${port}\n`);
const appApiUrl = new URL(this.adminApiUrl.href);
appApiUrl.port = port.toString();
const appWs = await AppWebsocket.connect({
Expand Down Expand Up @@ -513,7 +502,7 @@ export class Conductor {
installed_app_id,
network_seed,
};
this._logger.debug(
logger.debug(
`installing app with id ${installed_app_id} for agent ${encodeHashToBase64(
agent_key,
)}`,
Expand Down Expand Up @@ -542,7 +531,7 @@ export const cleanAllConductors = async () => {
const conductorProcess = spawn("hc", ["sandbox", "clean"]);
return new Promise<void>((resolve) => {
conductorProcess.stdout.once("end", () => {
defaultLogger.debug("sandbox conductors cleaned\n");
logger.debug("sandbox conductors cleaned\n");
resolve();
});
});
Expand Down
Loading