Skip to content

CSHARP-5280: Fix `server-selection/tests/logging/operation-id.json:Fa… #1523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions specifications/server-selection/tests/logging/operation-id.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
}
}
],
"_yamlAnchors": {
"namespace": "logging-tests.server-selection"
},
"tests": [
{
"description": "Successful bulkWrite operation: log messages have operationIds",
Expand Down Expand Up @@ -224,6 +227,192 @@
]
}
]
},
{
"description": "Successful client bulkWrite operation: log messages have operationIds",
"runOnRequirements": [
{
"minServerVersion": "8.0",
"serverless": "forbid"
}
],
"operations": [
{
"name": "waitForEvent",
"object": "testRunner",
"arguments": {
"client": "client",
"event": {
"topologyDescriptionChangedEvent": {}
},
"count": 2
}
},
{
"name": "clientBulkWrite",
"object": "client",
"arguments": {
"models": [
{
"insertOne": {
"namespace": "logging-tests.server-selection",
"document": {
"x": 1
}
}
}
]
}
}
],
"expectLogMessages": [
{
"client": "client",
"messages": [
{
"level": "debug",
"component": "serverSelection",
"data": {
"message": "Server selection started",
"operationId": {
"$$type": [
"int",
"long"
]
},
"operation": "bulkWrite"
}
},
{
"level": "debug",
"component": "serverSelection",
"data": {
"message": "Server selection succeeded",
"operationId": {
"$$type": [
"int",
"long"
]
},
"operation": "bulkWrite"
}
}
]
}
]
},
{
"description": "Failed client bulkWrite operation: log messages have operationIds",
"runOnRequirements": [
{
"minServerVersion": "8.0",
"serverless": "forbid"
}
],
"operations": [
{
"name": "failPoint",
"object": "testRunner",
"arguments": {
"client": "failPointClient",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": "alwaysOn",
"data": {
"failCommands": [
"hello",
"ismaster"
],
"appName": "loggingClient",
"closeConnection": true
}
}
}
},
{
"name": "waitForEvent",
"object": "testRunner",
"arguments": {
"client": "client",
"event": {
"serverDescriptionChangedEvent": {
"newDescription": {
"type": "Unknown"
}
}
},
"count": 1
}
},
{
"name": "clientBulkWrite",
"object": "client",
"arguments": {
"models": [
{
"insertOne": {
"namespace": "logging-tests.server-selection",
"document": {
"x": 1
}
}
}
]
},
"expectError": {
"isClientError": true
}
}
],
"expectLogMessages": [
{
"client": "client",
"messages": [
{
"level": "debug",
"component": "serverSelection",
"data": {
"message": "Server selection started",
"operationId": {
"$$type": [
"int",
"long"
]
},
"operation": "bulkWrite"
}
},
{
"level": "info",
"component": "serverSelection",
"data": {
"message": "Waiting for suitable server to become available",
"operationId": {
"$$type": [
"int",
"long"
]
},
"operation": "bulkWrite"
}
},
{
"level": "debug",
"component": "serverSelection",
"data": {
"message": "Server selection failed",
"operationId": {
"$$type": [
"int",
"long"
]
},
"operation": "bulkWrite"
}
}
]
}
]
}
]
}
99 changes: 99 additions & 0 deletions specifications/server-selection/tests/logging/operation-id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ createEntities:
- client:
id: &failPointClient failPointClient

_yamlAnchors:
namespace: &namespace "logging-tests.server-selection"

tests:
- description: "Successful bulkWrite operation: log messages have operationIds"
operations:
Expand Down Expand Up @@ -122,3 +125,99 @@ tests:
operationId: { $$type: [int, long] }
operation: insert

- description: "Successful client bulkWrite operation: log messages have operationIds"
runOnRequirements:
- minServerVersion: "8.0" # required for bulkWrite command
serverless: forbid
operations:
# ensure we've discovered the server so it is immediately available
# and no extra "waiting for suitable server" messages are emitted.
# expected topology events reflect initial server discovery and server connect event.
- name: waitForEvent
object: testRunner
arguments:
client: *client
event:
topologyDescriptionChangedEvent: {}
count: 2
- name: clientBulkWrite
object: *client
arguments:
models:
- insertOne:
namespace: *namespace
document: { x: 1 }
expectLogMessages:
- client: *client
messages:
- level: debug
component: serverSelection
data:
message: "Server selection started"
operationId: { $$type: [int, long] }
operation: bulkWrite
- level: debug
component: serverSelection
data:
message: "Server selection succeeded"
operationId: { $$type: [int, long] }
operation: bulkWrite

- description: "Failed client bulkWrite operation: log messages have operationIds"
runOnRequirements:
- minServerVersion: "8.0" # required for bulkWrite command
serverless: forbid
operations:
# fail all hello/legacy hello commands for the main client.
- name: failPoint
object: testRunner
arguments:
client: *failPointClient
failPoint:
configureFailPoint: failCommand
mode: alwaysOn
data:
failCommands: ["hello", "ismaster"]
appName: *appName
closeConnection: true
# wait until we've marked the server unknown due
# to a failed heartbeat.
- name: waitForEvent
object: testRunner
arguments:
client: *client
event:
serverDescriptionChangedEvent:
newDescription:
type: Unknown
count: 1
- name: clientBulkWrite
object: *client
arguments:
models:
- insertOne:
namespace: *namespace
document: { x: 1 }
expectError:
isClientError: true # server selection timeout
expectLogMessages:
- client: *client
messages:
- level: debug
component: serverSelection
data:
message: "Server selection started"
operationId: { $$type: [int, long] }
operation: bulkWrite
- level: info
component: serverSelection
data:
message: "Waiting for suitable server to become available"
operationId: { $$type: [int, long] }
operation: bulkWrite
- level: debug
component: serverSelection
data:
message: "Server selection failed"
operationId: { $$type: [int, long] }
operation: bulkWrite
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver.Core.Bindings;
using MongoDB.Driver.Core.Connections;
using MongoDB.Driver.Core.Events;
using MongoDB.Driver.Core.Misc;
using MongoDB.Driver.Core.WireProtocol.Messages;
using MongoDB.Driver.Core.WireProtocol.Messages.Encoders;
Expand Down Expand Up @@ -90,6 +91,7 @@ protected override IEnumerable<BatchableCommandMessageSection> CreateCommandPayl

public new ClientBulkWriteResult Execute(IWriteBinding binding, CancellationToken cancellationToken)
{
using var operation = BeginOperation();
var bulkWriteResults = new BulkWriteRawResult();
while (true)
{
Expand Down Expand Up @@ -146,6 +148,7 @@ protected override IEnumerable<BatchableCommandMessageSection> CreateCommandPayl

public new async Task<ClientBulkWriteResult> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
{
using var operation = BeginOperation();
var bulkWriteResults = new BulkWriteRawResult();
while (true)
{
Expand Down Expand Up @@ -200,6 +203,8 @@ protected override IEnumerable<BatchableCommandMessageSection> CreateCommandPayl
}
}

private IDisposable BeginOperation() => EventContext.BeginOperation(null, "bulkWrite");

private void EnsureCanProceedNextBatch(ConnectionId connectionId, BulkWriteRawResult bulkWriteResult)
{
if (bulkWriteResult.TopLevelException != null)
Expand Down