{
  "description": "retryable writes handshake failures",
  "schemaVersion": "1.4",
  "runOnRequirements": [
    {
      "minServerVersion": "4.2",
      "topologies": [
        "replicaset",
        "sharded",
        "load-balanced"
      ],
      "auth": true
    }
  ],
  "createEntities": [
    {
      "client": {
        "id": "client",
        "useMultipleMongoses": false,
        "observeEvents": [
          "connectionCheckOutStartedEvent",
          "commandStartedEvent",
          "commandSucceededEvent",
          "commandFailedEvent"
        ]
      }
    },
    {
      "database": {
        "id": "database",
        "client": "client",
        "databaseName": "retryable-writes-handshake-tests"
      }
    },
    {
      "collection": {
        "id": "collection",
        "database": "database",
        "collectionName": "coll"
      }
    }
  ],
  "initialData": [
    {
      "collectionName": "coll",
      "databaseName": "retryable-writes-handshake-tests",
      "documents": [
        {
          "_id": 1,
          "x": 11
        }
      ]
    }
  ],
  "tests": [
    {
      "description": "client.clientBulkWrite succeeds after retryable handshake network error",
      "runOnRequirements": [
        {
          "minServerVersion": "8.0",
          "serverless": "forbid"
        }
      ],
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "clientBulkWrite",
          "object": "client",
          "arguments": {
            "models": [
              {
                "insertOne": {
                  "namespace": "retryable-writes-handshake-tests.coll",
                  "document": {
                    "_id": 8,
                    "x": 88
                  }
                }
              }
            ]
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "bulkWrite"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "bulkWrite"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "client.clientBulkWrite succeeds after retryable handshake server error (ShutdownInProgress)",
      "runOnRequirements": [
        {
          "minServerVersion": "8.0",
          "serverless": "forbid"
        }
      ],
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "clientBulkWrite",
          "object": "client",
          "arguments": {
            "models": [
              {
                "insertOne": {
                  "namespace": "retryable-writes-handshake-tests.coll",
                  "document": {
                    "_id": 8,
                    "x": 88
                  }
                }
              }
            ]
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "bulkWrite"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "bulkWrite"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.insertOne succeeds after retryable handshake network error",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 2,
              "x": 22
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "insert"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "insert"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.insertOne succeeds after retryable handshake server error (ShutdownInProgress)",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 2,
              "x": 22
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "insert"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "insert"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.insertMany succeeds after retryable handshake network error",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "insertMany",
          "object": "collection",
          "arguments": {
            "documents": [
              {
                "_id": 2,
                "x": 22
              }
            ]
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "insert"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "insert"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.insertMany succeeds after retryable handshake server error (ShutdownInProgress)",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "insertMany",
          "object": "collection",
          "arguments": {
            "documents": [
              {
                "_id": 2,
                "x": 22
              }
            ]
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "insert"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "insert"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.deleteOne succeeds after retryable handshake network error",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "deleteOne",
          "object": "collection",
          "arguments": {
            "filter": {}
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "delete"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "delete"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.deleteOne succeeds after retryable handshake server error (ShutdownInProgress)",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "deleteOne",
          "object": "collection",
          "arguments": {
            "filter": {}
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "delete"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "delete"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.replaceOne succeeds after retryable handshake network error",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "replaceOne",
          "object": "collection",
          "arguments": {
            "filter": {},
            "replacement": {
              "x": 22
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "update"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "update"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.replaceOne succeeds after retryable handshake server error (ShutdownInProgress)",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "replaceOne",
          "object": "collection",
          "arguments": {
            "filter": {},
            "replacement": {
              "x": 22
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "update"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "update"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.updateOne succeeds after retryable handshake network error",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "updateOne",
          "object": "collection",
          "arguments": {
            "filter": {},
            "update": {
              "$set": {
                "x": 22
              }
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "update"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "update"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.updateOne succeeds after retryable handshake server error (ShutdownInProgress)",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "updateOne",
          "object": "collection",
          "arguments": {
            "filter": {},
            "update": {
              "$set": {
                "x": 22
              }
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "update"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "update"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.findOneAndDelete succeeds after retryable handshake network error",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "findOneAndDelete",
          "object": "collection",
          "arguments": {
            "filter": {}
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "findAndModify"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "findAndModify"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.findOneAndDelete succeeds after retryable handshake server error (ShutdownInProgress)",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "findOneAndDelete",
          "object": "collection",
          "arguments": {
            "filter": {}
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "findAndModify"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "findAndModify"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.findOneAndReplace succeeds after retryable handshake network error",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "findOneAndReplace",
          "object": "collection",
          "arguments": {
            "filter": {},
            "replacement": {
              "x": 22
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "findAndModify"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "findAndModify"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.findOneAndReplace succeeds after retryable handshake server error (ShutdownInProgress)",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "findOneAndReplace",
          "object": "collection",
          "arguments": {
            "filter": {},
            "replacement": {
              "x": 22
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "findAndModify"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "findAndModify"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.findOneAndUpdate succeeds after retryable handshake network error",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "findOneAndUpdate",
          "object": "collection",
          "arguments": {
            "filter": {},
            "update": {
              "$set": {
                "x": 22
              }
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "findAndModify"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "findAndModify"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.findOneAndUpdate succeeds after retryable handshake server error (ShutdownInProgress)",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "findOneAndUpdate",
          "object": "collection",
          "arguments": {
            "filter": {},
            "update": {
              "$set": {
                "x": 22
              }
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "findAndModify"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "findAndModify"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.bulkWrite succeeds after retryable handshake network error",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "bulkWrite",
          "object": "collection",
          "arguments": {
            "requests": [
              {
                "insertOne": {
                  "document": {
                    "_id": 2,
                    "x": 22
                  }
                }
              }
            ]
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "insert"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "insert"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "collection.bulkWrite succeeds after retryable handshake server error (ShutdownInProgress)",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "client",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "ping",
                  "saslContinue"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "name": "runCommand",
          "object": "database",
          "arguments": {
            "commandName": "ping",
            "command": {
              "ping": 1
            }
          },
          "expectError": {
            "isError": true
          }
        },
        {
          "name": "bulkWrite",
          "object": "collection",
          "arguments": {
            "requests": [
              {
                "insertOne": {
                  "document": {
                    "_id": 2,
                    "x": 22
                  }
                }
              }
            ]
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "eventType": "cmap",
          "events": [
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            },
            {
              "connectionCheckOutStartedEvent": {}
            }
          ]
        },
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "ping": 1
                },
                "databaseName": "retryable-writes-handshake-tests"
              }
            },
            {
              "commandFailedEvent": {
                "commandName": "ping"
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "insert"
              }
            },
            {
              "commandSucceededEvent": {
                "commandName": "insert"
              }
            }
          ]
        }
      ]
    }
  ]
}
