fix JSON flaky tests (#15261)

Co-authored-by: simonh5 <simonh5@illinois.edu>
This commit is contained in:
Simon Hofbauer 2023-10-26 22:27:09 -05:00 committed by GitHub
parent f1132d20c5
commit e9b7e4a0eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 15 deletions

View File

@ -240,12 +240,14 @@ public class EmitterTest
request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE)
); );
Assert.assertEquals( Assert.assertEquals(
StringUtils.format( JSON_MAPPER.readTree(StringUtils.format(
"[%s,%s]\n", "[%s,%s]\n",
JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(0)),
JSON_MAPPER.writeValueAsString(events.get(1)) JSON_MAPPER.writeValueAsString(events.get(1))
), )),
JSON_MAPPER.readTree(
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)
); );
return GoHandlers.immediateFuture(okResponse()); return GoHandlers.immediateFuture(okResponse());
@ -282,12 +284,14 @@ public class EmitterTest
request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE)
); );
Assert.assertEquals( Assert.assertEquals(
StringUtils.format( JSON_MAPPER.readTree(StringUtils.format(
"[%s,%s]\n", "[%s,%s]\n",
JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(0)),
JSON_MAPPER.writeValueAsString(events.get(1)) JSON_MAPPER.writeValueAsString(events.get(1))
), )),
JSON_MAPPER.readTree(
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)
); );
return GoHandlers.immediateFuture(okResponse()); return GoHandlers.immediateFuture(okResponse());
@ -467,12 +471,14 @@ public class EmitterTest
request.getHeaders().get(HttpHeaders.Names.AUTHORIZATION) request.getHeaders().get(HttpHeaders.Names.AUTHORIZATION)
); );
Assert.assertEquals( Assert.assertEquals(
StringUtils.format( JSON_MAPPER.readTree(StringUtils.format(
"%s\n%s\n", "%s\n%s\n",
JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(0)),
JSON_MAPPER.writeValueAsString(events.get(1)) JSON_MAPPER.writeValueAsString(events.get(1))
), )),
JSON_MAPPER.readTree(
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)
); );
return GoHandlers.immediateFuture(okResponse()); return GoHandlers.immediateFuture(okResponse());
@ -521,12 +527,14 @@ public class EmitterTest
request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE)
); );
Assert.assertEquals( Assert.assertEquals(
StringUtils.format( JSON_MAPPER.readTree(StringUtils.format(
"[%s,%s]\n", "[%s,%s]\n",
JSON_MAPPER.writeValueAsString(events.get(counter.getAndIncrement())), JSON_MAPPER.writeValueAsString(events.get(counter.getAndIncrement())),
JSON_MAPPER.writeValueAsString(events.get(counter.getAndIncrement())) JSON_MAPPER.writeValueAsString(events.get(counter.getAndIncrement()))
), )),
JSON_MAPPER.readTree(
StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString()
)
); );
return GoHandlers.immediateFuture(okResponse()); return GoHandlers.immediateFuture(okResponse());
@ -584,12 +592,14 @@ public class EmitterTest
CompressionUtils.gunzip(new ByteArrayInputStream(dataArray), baos); CompressionUtils.gunzip(new ByteArrayInputStream(dataArray), baos);
Assert.assertEquals( Assert.assertEquals(
StringUtils.format( JSON_MAPPER.readTree(StringUtils.format(
"[%s,%s]\n", "[%s,%s]\n",
JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(0)),
JSON_MAPPER.writeValueAsString(events.get(1)) JSON_MAPPER.writeValueAsString(events.get(1))
), )),
JSON_MAPPER.readTree(
baos.toString(StandardCharsets.UTF_8.name()) baos.toString(StandardCharsets.UTF_8.name())
)
); );
return GoHandlers.immediateFuture(okResponse()); return GoHandlers.immediateFuture(okResponse());

View File

@ -155,7 +155,9 @@ public class ParametrizedUriEmitterTest
"http://example.com/test1", StringUtils.format("[%s]\n", JSON_MAPPER.writeValueAsString(events.get(0))), "http://example.com/test1", StringUtils.format("[%s]\n", JSON_MAPPER.writeValueAsString(events.get(0))),
"http://example.com/test2", StringUtils.format("[%s]\n", JSON_MAPPER.writeValueAsString(events.get(1))) "http://example.com/test2", StringUtils.format("[%s]\n", JSON_MAPPER.writeValueAsString(events.get(1)))
); );
Assert.assertEquals(expected, results); for (Map.Entry<String, String> entry : expected.entrySet()) {
Assert.assertEquals(JSON_MAPPER.readTree(expected.get(entry.getKey())), JSON_MAPPER.readTree(results.get(entry.getKey())));
}
} }
@Test @Test