summaryrefslogtreecommitdiffstats
path: root/test/backend-test/test-rabbitmq.js
blob: 5782ef250817a796a63b72e7809f453db9993ff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { describe, test } = require("node:test");
const assert = require("node:assert");
const { RabbitMQContainer } = require("@testcontainers/rabbitmq");
const { RabbitMqMonitorType } = require("../../server/monitor-types/rabbitmq");
const { UP, DOWN, PENDING } = require("../../src/util");

describe("RabbitMQ Single Node", {
    skip: !!process.env.CI && (process.platform !== "linux" || process.arch !== "x64"),
}, () => {
    test("RabbitMQ is running", async () => {
        // The default timeout of 30 seconds might not be enough for the container to start
        const rabbitMQContainer = await new RabbitMQContainer().withStartupTimeout(60000).start();
        const rabbitMQMonitor = new RabbitMqMonitorType();
        const connectionString = `http://${rabbitMQContainer.getHost()}:${rabbitMQContainer.getMappedPort(15672)}`;

        const monitor = {
            rabbitmqNodes: JSON.stringify([ connectionString ]),
            rabbitmqUsername: "guest",
            rabbitmqPassword: "guest",
        };

        const heartbeat = {
            msg: "",
            status: PENDING,
        };

        try {
            await rabbitMQMonitor.check(monitor, heartbeat, {});
            assert.strictEqual(heartbeat.status, UP);
            assert.strictEqual(heartbeat.msg, "OK");
        } finally {
            rabbitMQContainer.stop();
        }
    });

    test("RabbitMQ is not running", async () => {
        const rabbitMQMonitor = new RabbitMqMonitorType();
        const monitor = {
            rabbitmqNodes: JSON.stringify([ "http://localhost:15672" ]),
            rabbitmqUsername: "rabbitmqUser",
            rabbitmqPassword: "rabbitmqPass",
        };

        const heartbeat = {
            msg: "",
            status: PENDING,
        };

        await rabbitMQMonitor.check(monitor, heartbeat, {});
        assert.strictEqual(heartbeat.status, DOWN);
    });

});