-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
inject-test.js
99 lines (89 loc) · 3.35 KB
/
inject-test.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// This is a k6 script that can be used to test the kumomta http
// injection API endpoint.
import http from "k6/http";
import encoding from "k6/encoding";
import { check } from "k6";
// Whether to use the builder mode of the API, which is where the request
// defines the various parts and attachments and defers to kumomta to
// build the actual MIME message. This convenience costs CPUs on the
// kumomta node, generally cutting injection rate by about half when
// using it.
const use_builder = true;
// The number of recipients to include in any given request
const batch_size = 100;
// Whether deferred_spool should be used.
// Setting deferred_spool=true can boost performance but comes with
// the risk of the loss of accountability if the service crashes
const deferred_spool = false;
// Whether deferred_generation should be used.
// This causes the generation to complete asynchronously wrt. the
// injection request.
const deferred_generation = true;
// Whether the client should compress the request body.
// KumoMTA does not currently support this on the server side,
// so enabling this will fail
const compression = false;
// How large the generated messages should be
const payload_size = 100000;
export const options = {
// How many concurrent connections should be established
vus: 40,
// How long the test should run for
duration: '30s',
};
// ---- there's no easy configuration beyond this point
const nonsense = "akjhasdlfkjhl kajsdhfl kjh lkajsdhflkjh asdkjfh asdf\n";
const num_lines = (payload_size / 2) / nonsense.length;
const lines = nonsense.repeat(num_lines);
const big_lines = nonsense.repeat(num_lines * 2);
export default function () {
// const credentials = "scott:tiger";
// const encodedCredentials = encoding.b64encode(credentials);
const url = "http://127.0.0.1:8000/api/inject/v1";
const content = use_builder ? {
text_body: lines,
html_body: lines,
from: {
email: "info@testing.mx-sink.wezfurlong.org",
name: "Test",
},
subject: "This is the subject from k6",
reply_to: {
email: "reply@testing.mx-sink.wezfurlong.org",
name: "k6-test",
},
} : `Subject: woot\nFrom: wez@testing.mx-sink.wezfurlong.org\n\n{big_lines}`;
var recipients = [];
for (var i = 0; i < batch_size; i++) {
var rand = Math.floor(Math.random() * 100000000) + 1; // get b between 1 and 1000
if (rand < 70000000) {
var domain = "gmail.com.mx-sink.wezfurlong.org";
} else if (rand > 70000000 && rand < 90000000) {
var domain = "yahoo.com.mx-sink.wezfurlong.org";
} else {
var domain = "aol.com.mx-sink.wezfurlong.org";
}
recipients.push({email: `someone-${i}@${domain}`});
}
const payload = JSON.stringify({
envelope_sender: "sender@testing.mx-sink.wezfurlong.org",
content: content,
recipients: recipients,
deferred_spool: deferred_spool,
deferred_generation: deferred_generation,
});
const params = {
headers: {
"Content-Type": "application/json",
// Authorization: `Basic ${encodedCredentials}`,
// "Accept-Encoding": "deflate",
},
compression: compression ? "deflate" : "",
};
let response = http.post(url, payload, params);
// console.log(response);
check(response, {
"is status 200": (r) => r.status === 200,
"success_count present in output": (r) => r.json().success_count >= 0,
});
}