Skip to content

Commit

Permalink
Follow unacknowledged write with a find in spec tests (#1355)
Browse files Browse the repository at this point in the history
This will force completion of the unacknowledged write, which addresses
a TCP-based race condition in the tests

JAVA-5398
  • Loading branch information
jyemin authored Apr 3, 2024
1 parent adffc61 commit c8ce9ae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"description": "command-logging",
"schemaVersion": "1.13",
"description": "unacknowledged-write",
"schemaVersion": "1.16",
"createEntities": [
{
"client": {
Expand Down Expand Up @@ -53,11 +53,27 @@
"_id": 2
}
}
},
{
"name": "find",
"object": "collection",
"arguments": {
"filter": {}
},
"expectResult": [
{
"_id": 1
},
{
"_id": 2
}
]
}
],
"expectLogMessages": [
{
"client": "client",
"ignoreExtraMessages": true,
"messages": [
{
"level": "debug",
Expand Down Expand Up @@ -132,5 +148,3 @@
}
]
}


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"description": "unacknowledgedBulkWrite",
"schemaVersion": "1.0",
"schemaVersion": "1.7",
"createEntities": [
{
"client": {
Expand Down Expand Up @@ -64,11 +64,29 @@
],
"ordered": false
}
},
{
"name": "find",
"object": "collection",
"arguments": {
"filter": {}
},
"expectResult": [
{
"_id": 1,
"x": 11
},
{
"_id": "unorderedBulkWriteInsertW0",
"x": 44
}
]
}
],
"expectEvents": [
{
"client": "client",
"ignoreExtraEvents": true,
"events": [
{
"commandStartedEvent": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

final class LogMatcher {
private final ValueMatcher valueMatcher;
Expand All @@ -46,11 +47,16 @@ final class LogMatcher {
this.context = context;
}

void assertLogMessageEquality(final String client, final BsonArray expectedMessages, final List<LogMessage> actualMessages,
final Iterable<Tweak> tweaks) {
void assertLogMessageEquality(final String client, final boolean ignoreExtraMessages, final BsonArray expectedMessages,
final List<LogMessage> actualMessages, final Iterable<Tweak> tweaks) {
context.push(ContextElement.ofLogMessages(client, expectedMessages, actualMessages));

assertEquals(context.getMessage("Number of log messages must be the same"), expectedMessages.size(), actualMessages.size());
if (ignoreExtraMessages) {
assertTrue(context.getMessage("Number of messages must be greater than or equal to the expected number of messages"),
actualMessages.size() >= expectedMessages.size());
} else {
assertEquals(context.getMessage("Number of log messages must be the same"), expectedMessages.size(), actualMessages.size());
}

for (int i = 0; i < expectedMessages.size(); i++) {
BsonDocument expectedMessage = expectedMessages.get(i).asDocument().clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,12 @@ private void compareLogMessages(final UnifiedTestContext rootContext, final Bson
final Iterable<LogMatcher.Tweak> tweaks) {
for (BsonValue cur : definition.getArray("expectLogMessages")) {
BsonDocument curLogMessagesForClient = cur.asDocument();
boolean ignoreExtraMessages = curLogMessagesForClient.getBoolean("ignoreExtraMessages", BsonBoolean.FALSE).getValue();
String clientId = curLogMessagesForClient.getString("client").getValue();
TestLoggingInterceptor loggingInterceptor =
entities.getClientLoggingInterceptor(clientId);
rootContext.getLogMatcher().assertLogMessageEquality(clientId, curLogMessagesForClient.getArray("messages"),
loggingInterceptor.getMessages(), tweaks);
rootContext.getLogMatcher().assertLogMessageEquality(clientId, ignoreExtraMessages,
curLogMessagesForClient.getArray("messages"), loggingInterceptor.getMessages(), tweaks);
}
}

Expand Down

0 comments on commit c8ce9ae

Please sign in to comment.