Skip to content

Commit

Permalink
test: backport missing tests from v20.x
Browse files Browse the repository at this point in the history
PR-URL: #212
Reviewed-by: Trevor Norris <[email protected]>
  • Loading branch information
santigimeno authored and trevnorris committed Nov 5, 2024
1 parent bcbe6a8 commit 1d60b95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions test/agents/test-grpc-metrics.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Flags: --expose-internals
import { mustSucceed } from '../common/index.mjs';
import { mustCall, mustSucceed } from '../common/index.mjs';
import assert from 'node:assert';
import { setTimeout } from 'node:timers/promises';
import {
checkResource,
GRPCServer,
Expand Down Expand Up @@ -174,7 +173,6 @@ function checkScopeMetrics(scopeMetrics) {
const [ name, unit, type, aggregation ] = expectedMetric;
const metric = metrics.find((m) => m.name === name);
assert.ok(metric, `Expected metric ${name} not found`);
console.dir(metric, { depth: null });
assert.strictEqual(metric.unit, unit);
assert.strictEqual(metric.data, aggregation);
const dataPoints = metric[aggregation].dataPoints;
Expand Down Expand Up @@ -210,7 +208,6 @@ function checkScopeMetrics(scopeMetrics) {
}

function checkMetricsData(msg, metadata, requestId, agentId, nsolidConfig, nsolidMetrics) {
console.dir(msg, { depth: null });
const metrics = msg;
assert.strictEqual(metrics.common.requestId, requestId);
assert.strictEqual(metrics.common.command, 'metrics');
Expand Down Expand Up @@ -241,13 +238,14 @@ async function runTest({ getEnv }) {
const child = new TestClient([], opts);
const agentId = await child.id();
const config = await child.config();
const metrics = await child.metrics();
await setTimeout(200);
const { data, requestId } = await grpcServer.metrics(agentId);
checkMetricsData(data.msg, data.metadata, requestId, agentId, config, metrics);
await child.shutdown(0);
grpcServer.close();
resolve();
grpcServer.once('metrics', mustCall(async () => {
const metrics = await child.metrics();
const { data, requestId } = await grpcServer.metrics(agentId);
checkMetricsData(data.msg, data.metadata, requestId, agentId, config, metrics);
await child.shutdown(0);
grpcServer.close();
resolve();
}));
}));
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/common/nsolid-grpc-agent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class GRPCServer extends EventEmitter {
if (this.#server) {
const requestId = randomUUID();
this.#server.send({ type: 'metrics', agentId, requestId });
this.#server.once('message', (msg) => {
this.#server.on('message', (msg) => {
if (msg.type === 'metrics_cmd') {
resolve({ requestId, data: msg.data });
}
Expand Down

0 comments on commit 1d60b95

Please sign in to comment.