Skip to content

Commit fc7e3b8

Browse files
committed
test: added test for flushing timeout
1 parent 06dcabd commit fc7e3b8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

test/Test.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void Test::run() {
5656
testFluxParserMissingDatatype();
5757
testFluxParserErrorInRow();
5858
testBasicFunction();
59+
testFlushing();
5960
testInit();
6061
testRepeatedInit();
6162
testV1();
@@ -2076,6 +2077,46 @@ void Test::testBuckets() {
20762077
TEST_END();
20772078
}
20782079

2080+
void Test::testFlushing() {
2081+
TEST_INIT("testFlushing");
2082+
InfluxDBClient client(Test::apiUrl, Test::orgName, Test::bucketName, Test::token);
2083+
TEST_ASSERT(waitServer(Test::managementUrl, true));
2084+
TEST_ASSERT(client.validateConnection());
2085+
TEST_ASSERT(!client.isBufferFull());
2086+
TEST_ASSERT(client.isBufferEmpty());
2087+
client.setWriteOptions(WriteOptions().batchSize(10).bufferSize(30).flushInterval(2));
2088+
2089+
for (int i = 0; i < 5; i++) {
2090+
Point *p = createPoint("test1");
2091+
p->addField("index", i);
2092+
TEST_ASSERT(client.writePoint(*p));
2093+
delete p;
2094+
}
2095+
TEST_ASSERT(!client.isBufferFull());
2096+
TEST_ASSERT(!client.isBufferEmpty());
2097+
client.checkBuffer();
2098+
TEST_ASSERT(!client.isBufferFull());
2099+
TEST_ASSERT(!client.isBufferEmpty());
2100+
String query = "select";
2101+
FluxQueryResult q = client.query(query);
2102+
int count = countLines(q);
2103+
TEST_ASSERTM(q.getError()=="", q.getError());
2104+
TEST_ASSERTM( count == 0, String(count) + " vs 0"); //5 points
2105+
2106+
delay(2100);
2107+
client.checkBuffer();
2108+
TEST_ASSERT(!client.isBufferFull());
2109+
TEST_ASSERT(client.isBufferEmpty());
2110+
2111+
q = client.query(query);
2112+
count = countLines(q);
2113+
TEST_ASSERTM(q.getError()=="", q.getError());
2114+
TEST_ASSERTM( count == 5, String(count) + " vs 0"); //5 points
2115+
2116+
TEST_END();
2117+
deleteAll(Test::apiUrl);
2118+
}
2119+
20792120
void Test::setServerUrl(InfluxDBClient &client, String serverUrl) {
20802121
client._connInfo.serverUrl = serverUrl;
20812122
client._service->_apiURL = serverUrl + "/api/v2/";

test/Test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Test : public TestBase {
7070
static void testRepeatedInit();
7171
static void testIsValidID();
7272
static void testBuckets();
73+
static void testFlushing();
7374
};
7475

7576
#endif //_TEST_H_

0 commit comments

Comments
 (0)