Skip to content

Commit

Permalink
fix: redirect according to status
Browse files Browse the repository at this point in the history
  • Loading branch information
rorlic committed Apr 9, 2024
1 parent 852487a commit 9995547
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ export class Controller {
return !!test && test.run.status === TestRunStatus.running;
}

public testStatus(id: string): TestRunStatus | undefined {
const test = this._getTest(id);
return test && test.run.status;
}

public cancelTest(id: string) {
const test = this._getTest(id);
if (test) {
Expand Down
18 changes: 12 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'node:fs';
import { Registry, collectDefaultMetrics } from 'prom-client';

import { Controller } from './controller';
import { ControllerConfig } from './interfaces';
import { ControllerConfig, TestRunStatus } from './interfaces';

const megabyte = 1048576;
const server = fastify({ bodyLimit: 10 * megabyte });
Expand Down Expand Up @@ -140,11 +140,17 @@ server.get('/:id', { schema: { querystring: { limit: { type: 'number' } } } }, a
const { id } = request.params as { id: string };

try {
if (controller.testExists(id)) {
const body = await controller.getTestRunStatus(id, parameters.limit);
return reply.header('content-type', 'text/html').send(body);
} else {
return reply.status(404).send('');
switch (controller.testStatus(id)) {
case TestRunStatus.running: {
const body = await controller.getTestRunStatus(id, parameters.limit);
return reply.header('content-type', 'text/html').send(body);
}
case TestRunStatus.cancelled:
return reply.redirect(`/test/${id}/jmeter.log`);
case TestRunStatus.done:
return reply.redirect(`/test/${id}/results/`);
default:
return reply.status(404).send('');
}
} catch (error) {
return reply.status(500).send({ msg: `Cannot display status for test run ${id}\n`, error: error });
Expand Down

0 comments on commit 9995547

Please sign in to comment.