forked from snowplow/snowplow-cpp-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemitter_test.cpp
More file actions
73 lines (55 loc) · 2.06 KB
/
Copy pathemitter_test.cpp
File metadata and controls
73 lines (55 loc) · 2.06 KB
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
/*
Copyright (c) 2016 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License Version 2.0.
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing,
software distributed under the Apache License Version 2.0 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
#include "../vendored/catch.hpp"
#include "../emitter.hpp"
TEST_CASE("emitter") {
Emitter emitter("ea2673c7.ngrok.io", Emitter::Strategy::ASYNC, Emitter::Method::POST, Emitter::Protocol::HTTP, 500, 52000, 52000, "test.db");
emitter.start();
Payload payload;
payload.add("e", "pv");
payload.add("tv", "cpp-0.1.0");
payload.add("p", "srv");
payload.add("dtm", std::to_string(Utils::get_unix_epoch_ms()));
const int send_events_per_thread = 1000;
const int thread_count = 10;
vector<thread> threads;
for (int j = 0; j < thread_count; j++) {
threads.push_back(thread([=](Emitter & e) {
Payload payload2;
payload2.add("e", "pv");
payload2.add("tv", "cpp-0.1.0");
payload2.add("p", "srv");
payload2.add("dtm", std::to_string(Utils::get_unix_epoch_ms()));
for (int i = 0; i < send_events_per_thread; i++)
{
e.add(payload2);
}
}, std::ref(emitter)));
}
for (unsigned int j = 0; j < threads.size(); j++)
{
threads[j].join();
}
emitter.stop();
auto res = test_get_http_request_results();
int size = res.size();
int expected = send_events_per_thread*(thread_count + 1);
REQUIRE(size > expected);
// but does it start again
emitter.start();
for (int i = 0; i < 100; i++) {
emitter.add(payload);
}
emitter.stop();
res = test_get_http_request_results();
size = res.size();
REQUIRE(size > expected + 100);
}