tangled
alpha
login
or
join now
openstatus.dev
/
openstatus
5
fork
atom
Openstatus
www.openstatus.dev
5
fork
atom
overview
issues
pulls
pipelines
🧪 fix tests
Thibault Le Ouay
2 years ago
3a5054ec
74a234dc
+25
-28
4 changed files
expand all
collapse all
unified
split
.dockerignore
apps
server
fly.toml
src
checker
checker.test.ts
checker.ts
+2
-1
.dockerignore
···
4
4
**/README.md
5
5
**/.next
6
6
**/.git
7
7
-
node_modules
7
7
+
node_modules
8
8
+
openstatus.db
+2
-2
apps/server/fly.toml
···
14
14
internal_port = 3000
15
15
force_https = true
16
16
auto_stop_machines = false
17
17
-
auto_start_machines = true
18
18
-
min_machines_running = 2
17
17
+
auto_start_machines = false
18
18
+
min_machines_running = 12
19
19
processes = ["app"]
20
20
[http_service.concurrency]
21
21
type = "requests"
+18
-22
apps/server/src/checker/checker.test.ts
···
11
11
test("should call upsertMonitorStatus when we can fetch", async () => {
12
12
const fn = mock(() => {});
13
13
14
14
-
mock.module("./alerting.ts", () => {
14
14
+
mock.module("./monitor-handler.ts", () => {
15
15
return {
16
16
-
upsertMonitorStatus: fn,
16
16
+
handleMonitorFailed: mock(() => {}),
17
17
+
handleMonitorRecovered: fn,
17
18
};
18
19
});
20
20
+
19
21
await checkerRetryPolicy({
20
22
workspaceId: "1",
21
23
monitorId: "1",
···
31
33
test("should call upsertMonitorStatus when status error", async () => {
32
34
const fn = mock(() => {});
33
35
34
34
-
mock.module("./alerting.ts", () => {
36
36
+
mock.module("./monitor-handler.ts", () => {
35
37
return {
36
36
-
upsertMonitorStatus: fn,
38
38
+
handleMonitorFailed: fn,
39
39
+
handleMonitorRecovered: mock(() => {}),
37
40
};
38
41
});
39
42
try {
···
55
58
test("What should we do when redirect ", async () => {
56
59
const fn = mock(() => {});
57
60
58
58
-
mock.module("./alerting.ts", () => {
61
61
+
mock.module("./monitor-handler.ts", () => {
59
62
return {
60
60
-
upsertMonitorStatus: fn,
63
63
+
handleMonitorFailed: fn,
61
64
};
62
65
});
63
66
try {
···
79
82
test("When 404 we should trigger alerting ", async () => {
80
83
const fn = mock(() => {});
81
84
const fn1 = mock(() => {});
82
82
-
const fn2 = mock(() => {});
83
85
84
84
-
mock.module("./alerting.ts", () => {
86
86
+
mock.module("./ping.ts", () => {
85
87
return {
86
86
-
upsertMonitorStatus: fn,
87
87
-
triggerAlerting: fn1,
88
88
+
publishPing: fn,
88
89
};
89
90
});
90
90
-
mock.module("./ping.ts", () => {
91
91
+
mock.module("./monitor-handler.ts", () => {
91
92
return {
92
92
-
publishPing: fn2,
93
93
+
handleMonitorFailed: fn1,
93
94
};
94
95
});
95
96
try {
···
107
108
}
108
109
expect(fn).toHaveBeenCalledTimes(1);
109
110
expect(fn1).toHaveBeenCalledTimes(1);
110
110
-
expect(fn2).toHaveBeenCalledTimes(1);
111
111
});
112
112
113
113
test("When error 404 we should not trigger alerting ", async () => {
114
114
const fn = mock(() => {});
115
115
const fn1 = mock(() => {});
116
116
-
const fn2 = mock(() => {});
117
116
118
118
-
mock.module("./alerting.ts", () => {
117
117
+
mock.module("./ping.ts", () => {
119
118
return {
120
120
-
upsertMonitorStatus: fn,
121
121
-
triggerAlerting: fn1,
119
119
+
publishPing: fn,
122
120
};
123
121
});
124
124
-
125
125
-
mock.module("./ping.ts", () => {
122
122
+
mock.module("./monitor-handler.ts", () => {
126
123
return {
127
127
-
publishPing: fn2,
124
124
+
handleMonitorFailed: fn1,
128
125
};
129
126
});
130
127
try {
···
140
137
} catch (e) {
141
138
expect(e).toBeInstanceOf(Error);
142
139
}
143
143
-
expect(fn).toHaveBeenCalledTimes(0);
140
140
+
expect(fn).toHaveBeenCalledTimes(1);
144
141
expect(fn1).toHaveBeenCalledTimes(0);
145
145
-
expect(fn2).toHaveBeenCalledTimes(1);
146
142
});
+3
-3
apps/server/src/checker/checker.ts
···
75
75
message: undefined,
76
76
});
77
77
if (data?.status === "error") {
78
78
-
handleMonitorRecovered(data, res);
78
78
+
await handleMonitorRecovered(data, res);
79
79
}
80
80
} else {
81
81
if (retry < 2) {
···
94
94
statusCode: res?.status,
95
95
message,
96
96
});
97
97
-
if (data?.status === "active") {
98
98
-
handleMonitorFailed(data, res, message);
97
97
+
if (data.status === "active") {
98
98
+
await handleMonitorFailed(data, res, message);
99
99
}
100
100
}
101
101
}