Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Dec 5, 2023
1 parent f13c662 commit 116112a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface ExporterConfig {

export class PrometheusExporter extends MetricReader {
private readonly _abortController: AbortController;
private readonly _server: Deno.HttpServer;

// This will be required when histogram is implemented. Leaving here so it is not forgotten
// Histogram cannot have a attribute named 'le'
Expand All @@ -68,7 +69,7 @@ export class PrometheusExporter extends MetricReader {
this._abortController = new AbortController();
const { signal } = this._abortController;

Deno.serve({ hostname, port, signal, onError }, async (request) => {
this._server = Deno.serve({ hostname, port, signal, onError }, async (request) => {
if (new URL(request.url).pathname !== "/metrics") {
return new Response("not found", { status: 404 });
}
Expand Down Expand Up @@ -113,6 +114,6 @@ export class PrometheusExporter extends MetricReader {
*/
stopServer(): Promise<void> {
this._abortController.abort();
return Promise.resolve();
return this._server.finished;
}
}
4 changes: 3 additions & 1 deletion packages/autometrics/tests/otlpHttpExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Deno.test("OTLP/HTTP exporter", async (t) => {
// retrying, which may mess with other tests.
const serverController = new AbortController();
const { signal } = serverController;
Deno.serve({ port, signal }, () => new Response("ok"));
const server = Deno.serve({ port, signal }, () => new Response("ok"));

// make sure that metrics that are collected before `init()` is called are
// correctly tracked.
Expand Down Expand Up @@ -53,4 +53,6 @@ Deno.test("OTLP/HTTP exporter", async (t) => {
);

serverController.abort();

await server.finished;
});
4 changes: 3 additions & 1 deletion packages/autometrics/tests/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function testWithTemporality({
// retrying, which may mess with other tests.
const serverController = new AbortController();
const { signal } = serverController;
Deno.serve({ port, signal }, () => new Response("ok"));
const server = Deno.serve({ port, signal }, () => new Response("ok"));

const timeout = 10;

Expand Down Expand Up @@ -96,5 +96,7 @@ export function testWithTemporality({
await metricReader.shutdown();

serverController.abort();

await server.finished;
};
}

0 comments on commit 116112a

Please sign in to comment.