{
  "description": "MaxTimeMSExpired server errors are transformed into a custom timeout error",
  "schemaVersion": "1.9",
  "runOnRequirements": [
    {
      "minServerVersion": "4.0",
      "topologies": [
        "replicaset"
      ]
    },
    {
      "minServerVersion": "4.2",
      "topologies": [
        "replicaset",
        "sharded"
      ]
    }
  ],
  "createEntities": [
    {
      "client": {
        "id": "failPointClient",
        "useMultipleMongoses": false
      }
    },
    {
      "client": {
        "id": "client",
        "uriOptions": {
          "timeoutMS": 50
        },
        "useMultipleMongoses": false,
        "observeEvents": [
          "commandStartedEvent"
        ]
      }
    },
    {
      "database": {
        "id": "database",
        "client": "client",
        "databaseName": "test"
      }
    },
    {
      "collection": {
        "id": "collection",
        "database": "database",
        "collectionName": "coll"
      }
    }
  ],
  "initialData": [
    {
      "collectionName": "coll",
      "databaseName": "test",
      "documents": []
    }
  ],
  "tests": [
    {
      "description": "basic MaxTimeMSExpired error is transformed",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "failPointClient",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "insert"
                ],
                "errorCode": 50
              }
            }
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 1
            }
          },
          "expectError": {
            "isTimeoutError": true
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "commandName": "insert",
                "databaseName": "test",
                "command": {
                  "insert": "coll",
                  "maxTimeMS": {
                    "$$type": [
                      "int",
                      "long"
                    ]
                  }
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "write concern error MaxTimeMSExpired is transformed",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "failPointClient",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "insert"
                ],
                "writeConcernError": {
                  "code": 50,
                  "errmsg": "maxTimeMS expired"
                }
              }
            }
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 1
            }
          },
          "expectError": {
            "isTimeoutError": true
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "commandName": "insert",
                "databaseName": "test",
                "command": {
                  "insert": "coll",
                  "maxTimeMS": {
                    "$$type": [
                      "int",
                      "long"
                    ]
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ]
}
