Skip to content

Commit

Permalink
test(cardano-services): fixes 4 typos of --service-name argument
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed Mar 17, 2023
1 parent a9a3f0d commit 407da75
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions packages/cardano-services/test/cli.test.ts
Expand Up @@ -37,12 +37,16 @@ const assertServiceHealthy = async (
apiUrl: string,
serviceName: ServiceNames,
lastBlock: LedgerTipModel,
withTip = true,
usedQueue?: boolean
options?: {
unhealthy?: boolean;
usedQueue?: boolean;
withTip?: boolean;
}
) => {
await serverReady(apiUrl);
const headers = { 'Content-Type': 'application/json' };
const res = await axios.post(`${apiUrl}/${serviceName}/health`, { headers });
const { unhealthy, usedQueue, withTip } = { withTip: true, ...options };

const healthCheckResponse = usedQueue
? { ok: true }
Expand All @@ -56,7 +60,8 @@ const assertServiceHealthy = async (
});

expect(res.status).toBe(200);
expect(res.data).toEqual(healthCheckResponse);
if (unhealthy) expect(res.data.ok).toBeFalsy();
else expect(res.data).toEqual(healthCheckResponse);
};

const assertMetricsEndpoint = async (apiUrl: string, assertFound: boolean) => {
Expand Down Expand Up @@ -102,7 +107,7 @@ type CallCliAndAssertExitArgs = {
env?: NodeJS.ProcessEnv;
};

const baseArgs = ['start-provider-server', '--logger-min-severity', 'error'];
const baseArgs = ['start-provider-server', '--logger-min-severity', 'debug'];

const withLogging = (proc: ChildProcess, expectingExceptions = false): ChildProcess => {
const methodOnFailure = expectingExceptions ? 'debug' : 'error';
Expand Down Expand Up @@ -269,7 +274,7 @@ describe('CLI', () => {
await assertServiceHealthy(apiUrl, ServiceNames.ChainHistory, lastBlock);
await assertServiceHealthy(apiUrl, ServiceNames.NetworkInfo, lastBlock);
await assertServiceHealthy(apiUrl, ServiceNames.StakePool, lastBlock);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, false, false);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, { withTip: false });
await assertServiceHealthy(apiUrl, ServiceNames.Utxo, lastBlock);
await assertServiceHealthy(apiUrl, ServiceNames.Rewards, lastBlock);
});
Expand All @@ -295,7 +300,7 @@ describe('CLI', () => {
await assertServiceHealthy(apiUrl, ServiceNames.ChainHistory, lastBlock);
await assertServiceHealthy(apiUrl, ServiceNames.NetworkInfo, lastBlock);
await assertServiceHealthy(apiUrl, ServiceNames.StakePool, lastBlock);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, false, false);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, { withTip: false });
await assertServiceHealthy(apiUrl, ServiceNames.Utxo, lastBlock);
await assertServiceHealthy(apiUrl, ServiceNames.Rewards, lastBlock);
});
Expand Down Expand Up @@ -1329,7 +1334,7 @@ describe('CLI', () => {
stdio: 'pipe'
})
);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, false, false);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, { withTip: false });
});

it('tx-submit uses the default Ogmios configuration if not specified when using env variables', async () => {
Expand All @@ -1344,7 +1349,7 @@ describe('CLI', () => {
stdio: 'pipe'
})
);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, false, false);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, { withTip: false });
});
});

Expand Down Expand Up @@ -1440,7 +1445,7 @@ describe('CLI', () => {
ogmiosConnection.address.webSocket,
'--ogmios-srv-service-name',
ogmiosSrvServiceName,
'--service_names',
'--service-names',
ServiceNames.NetworkInfo
],
dataMatchOnError: CLI_CONFLICTING_OPTIONS_ERROR_MESSAGE
Expand Down Expand Up @@ -1473,7 +1478,7 @@ describe('CLI', () => {
ogmiosConnection.address.webSocket,
'--ogmios-srv-service-name',
ogmiosSrvServiceName,
'--service_names',
'--service-names',
ServiceNames.TxSubmit
],
dataMatchOnError: CLI_CONFLICTING_OPTIONS_ERROR_MESSAGE
Expand Down Expand Up @@ -1706,7 +1711,7 @@ describe('CLI', () => {
}
)
);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, true, true);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, { usedQueue: true });
});

it('exposes a HTTP server with healthy state when using env variables', async () => {
Expand All @@ -1722,7 +1727,7 @@ describe('CLI', () => {
stdio: 'pipe'
})
);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, true, true);
await assertServiceHealthy(apiUrl, ServiceNames.TxSubmit, lastBlock, { usedQueue: true });
});
});

Expand Down Expand Up @@ -1776,7 +1781,7 @@ describe('CLI', () => {
rabbitmqUrl.toString(),
'--service-discovery-timeout',
'1000',
'--service_names',
'--service-names',
ServiceNames.TxSubmit
],
dataMatchOnError: CLI_CONFLICTING_OPTIONS_ERROR_MESSAGE
Expand Down Expand Up @@ -1810,22 +1815,34 @@ describe('CLI', () => {
ogmiosServer = createUnhealthyMockOgmiosServer();
});

it('exits with code 1', (done) => {
ogmiosServer.listen(ogmiosConnection.port, () => {
callCliAndAssertExit(
{
args: [
it('starts and can be queried for health status', (done) => {
ogmiosServer.listen(ogmiosConnection.port, async () => {
proc = withLogging(
fork(
exePath,
[
...baseArgs,
'--api-url',
apiUrl,
'--postgres-connection-string',
postgresConnectionString,
'--cardano-node-config-path',
cardanoNodeConfigPath,
'--ogmios-url',
ogmiosConnection.address.webSocket,
'--service_names',
'--service-names',
ServiceNames.StakePool,
ServiceNames.TxSubmit
]
},
done
],
{
env: {},
stdio: 'pipe'
}
)
);

await assertServiceHealthy(apiUrl, ServiceNames.StakePool, lastBlock, { unhealthy: true });
done();
});
});
});
Expand Down

0 comments on commit 407da75

Please sign in to comment.