Skip to content

Commit bf592a2

Browse files
committed
Fix TLS tests failing with small(lots of) records
1 parent 8d4a619 commit bf592a2

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

test/unit_test.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ static int s_num_tests = 0;
88
#ifdef NO_SLEEP_ABORT
99
#define ABORT() abort()
1010
#else
11-
#define ABORT() \
12-
sleep(2); /* 2s, GH print reason */ \
13-
abort();
11+
#define ABORT() \
12+
sleep(2); /* 2s, GH print reason */ \
13+
abort();
1414
#endif
1515

1616
#define ASSERT(expr) \
@@ -365,8 +365,8 @@ static void test_sntp(void) {
365365
// NOTE(): historical NTP port blockage issue; expect at least one to be
366366
// reachable and work. https://github.com/actions/runner-images/issues/5615
367367
result = test_sntp_server("udp://time.apple.com:123") ||
368-
test_sntp_server("udp://time.windows.com:123") ||
369-
test_sntp_server(NULL);
368+
test_sntp_server("udp://time.windows.com:123") ||
369+
test_sntp_server(NULL);
370370
#if defined(NO_SNTP_CHECK)
371371
(void) result;
372372
#else
@@ -778,7 +778,7 @@ static int fetch(struct mg_mgr *mgr, char *buf, const char *url,
778778
mg_vprintf(c, fmt, &ap);
779779
va_end(ap);
780780
buf[0] = '\0';
781-
for (i = 0; i < 50 && buf[0] == '\0'; i++) mg_mgr_poll(mgr, 1);
781+
for (i = 0; i < 100 && buf[0] == '\0'; i++) mg_mgr_poll(mgr, 1);
782782
if (!fd.closed) c->is_closing = 1;
783783
mg_mgr_poll(mgr, 1);
784784
return fd.code;
@@ -1327,12 +1327,15 @@ static void test_tls(void) {
13271327
"Content-Length: %lu\n\n"
13281328
"%s",
13291329
data.len, data.buf) == 200);
1330-
// fire patched server, test multiple TLS records per TCP segment handling
1330+
// fire patched server, test multiple TLS records per TCP segment handling
13311331
{
13321332
ASSERT(system("tls_multirec/server -d tls_multirec &") == 0);
13331333
sleep(1);
1334-
ASSERT(fetch(&mgr, buf, "https://localhost:8443", "GET /thefile HTTP/1.0\n\n") == 200);
1335-
ASSERT(cmpbody(buf, data.buf) == 0); // "thefile" links to Makefile
1334+
// fetch() needs to loop enough times in order to process all TLS records;
1335+
// otherwise it will end with 200 and shorter file contents
1336+
ASSERT(fetch(&mgr, buf, "https://localhost:8443",
1337+
"GET /thefile HTTP/1.0\n\n") == 200);
1338+
ASSERT(cmpbody(buf, data.buf) == 0); // "thefile" links to Makefile
13361339
ASSERT(system("killall tls_multirec/server") == 0);
13371340
}
13381341
mg_mgr_free(&mgr);
@@ -1632,7 +1635,8 @@ static void test_http_parse(void) {
16321635
}
16331636

16341637
{
1635-
const char *s = "a b HTTP/1.0\r\nContent-Length: 21 \r\nb: t\r\nv:v\r\n\r\nabc";
1638+
const char *s =
1639+
"a b HTTP/1.0\r\nContent-Length: 21 \r\nb: t\r\nv:v\r\n\r\nabc";
16361640
ASSERT(mg_http_parse(s, strlen(s), &req) == (int) strlen(s) - 3);
16371641
ASSERT(req.body.len == 21);
16381642
ASSERT(req.message.len == 21 - 3 + strlen(s));
@@ -1692,7 +1696,8 @@ static void test_http_parse(void) {
16921696
}
16931697

16941698
{
1695-
static const char *s = "a b HTTP/1.0\na:1\nb:2\nc:3\nd:4\ne:5\nf:6\ng:7\nh:8\n\n";
1699+
static const char *s =
1700+
"a b HTTP/1.0\na:1\nb:2\nc:3\nd:4\ne:5\nf:6\ng:7\nh:8\n\n";
16961701
ASSERT(mg_http_parse(s, strlen(s), &req) == (int) strlen(s));
16971702
ASSERT((v = mg_http_get_header(&req, "e")) != NULL);
16981703
ASSERT(vcmp(*v, "5"));
@@ -2182,10 +2187,10 @@ static void test_str(void) {
21822187
TESTDOUBLE("%g", 0.01, "0.01");
21832188
TESTDOUBLE("%g", 0.001, "0.001");
21842189
TESTDOUBLE("%g", 0.0001, "0.0001");
2185-
TESTDOUBLE_NOHOSTCHECK("%g", 0.00001, "0.00001"); // "1e-05"
2190+
TESTDOUBLE_NOHOSTCHECK("%g", 0.00001, "0.00001"); // "1e-05"
21862191
TESTDOUBLE("%g", 0.000001, "1e-06");
21872192
TESTDOUBLE("%g", -0.0001, "-0.0001");
2188-
TESTDOUBLE_NOHOSTCHECK("%g", -0.00001, "-0.00001"); // "-1e-05"
2193+
TESTDOUBLE_NOHOSTCHECK("%g", -0.00001, "-0.00001"); // "-1e-05"
21892194
TESTDOUBLE("%g", 10.5454, "10.5454");
21902195
TESTDOUBLE("%g", 999999.0, "999999");
21912196
TESTDOUBLE("%g", 9999999.0, "1e+07");
@@ -2233,7 +2238,7 @@ static void test_str(void) {
22332238

22342239
TESTDOUBLE("%.3f", 13.12505, "13.125");
22352240
#if MG_ARCH == MG_ARCH_WIN32 && defined(_MSC_VER) && _MSC_VER < 1700
2236-
// TODO(): for some reason we round down in VC98; skip
2241+
// TODO(): for some reason we round down in VC98; skip
22372242
#else
22382243
TESTDOUBLE("%.3f", 15.1255, "15.126");
22392244
TESTDOUBLE("%.3f", 19.1255, "19.125");

0 commit comments

Comments
 (0)