{
  "description": "legacy timeouts continue to work if timeoutMS is not set",
  "schemaVersion": "1.0",
  "runOnRequirements": [
    {
      "minServerVersion": "4.4"
    }
  ],
  "initialData": [
    {
      "collectionName": "coll",
      "databaseName": "test",
      "documents": []
    }
  ],
  "tests": [
    {
      "description": "socketTimeoutMS is not used to derive a maxTimeMS command field",
      "operations": [
        {
          "name": "createEntities",
          "object": "testRunner",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client",
                  "observeEvents": [
                    "commandStartedEvent"
                  ],
                  "uriOptions": {
                    "socketTimeoutMS": 50000
                  }
                }
              },
              {
                "database": {
                  "id": "database",
                  "client": "client",
                  "databaseName": "test"
                }
              },
              {
                "collection": {
                  "id": "collection",
                  "database": "database",
                  "collectionName": "coll"
                }
              }
            ]
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "x": 1
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "commandName": "insert",
                "databaseName": "test",
                "command": {
                  "insert": "coll",
                  "maxTimeMS": {
                    "$$exists": false
                  }
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "waitQueueTimeoutMS is not used to derive a maxTimeMS command field",
      "operations": [
        {
          "name": "createEntities",
          "object": "testRunner",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client",
                  "observeEvents": [
                    "commandStartedEvent"
                  ],
                  "uriOptions": {
                    "waitQueueTimeoutMS": 50000
                  }
                }
              },
              {
                "database": {
                  "id": "database",
                  "client": "client",
                  "databaseName": "test"
                }
              },
              {
                "collection": {
                  "id": "collection",
                  "database": "database",
                  "collectionName": "coll"
                }
              }
            ]
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "x": 1
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "commandName": "insert",
                "databaseName": "test",
                "command": {
                  "insert": "coll",
                  "maxTimeMS": {
                    "$$exists": false
                  }
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "wTimeoutMS is not used to derive a maxTimeMS command field",
      "operations": [
        {
          "name": "createEntities",
          "object": "testRunner",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client",
                  "observeEvents": [
                    "commandStartedEvent"
                  ],
                  "uriOptions": {
                    "wTimeoutMS": 50000
                  }
                }
              },
              {
                "database": {
                  "id": "database",
                  "client": "client",
                  "databaseName": "test"
                }
              },
              {
                "collection": {
                  "id": "collection",
                  "database": "database",
                  "collectionName": "coll"
                }
              }
            ]
          }
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "x": 1
            }
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "commandName": "insert",
                "databaseName": "test",
                "command": {
                  "insert": "coll",
                  "maxTimeMS": {
                    "$$exists": false
                  },
                  "writeConcern": {
                    "wtimeout": 50000
                  }
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "maxTimeMS option is used directly as the maxTimeMS field on a command",
      "operations": [
        {
          "name": "createEntities",
          "object": "testRunner",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client",
                  "observeEvents": [
                    "commandStartedEvent"
                  ]
                }
              },
              {
                "database": {
                  "id": "database",
                  "client": "client",
                  "databaseName": "test"
                }
              },
              {
                "collection": {
                  "id": "collection",
                  "database": "database",
                  "collectionName": "coll"
                }
              }
            ]
          }
        },
        {
          "name": "estimatedDocumentCount",
          "object": "collection",
          "arguments": {
            "maxTimeMS": 50000
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "commandName": "count",
                "databaseName": "test",
                "command": {
                  "count": "coll",
                  "maxTimeMS": 50000
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "maxCommitTimeMS option is used directly as the maxTimeMS field on a commitTransaction command",
      "runOnRequirements": [
        {
          "topologies": [
            "replicaset",
            "sharded"
          ]
        }
      ],
      "operations": [
        {
          "name": "createEntities",
          "object": "testRunner",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client",
                  "observeEvents": [
                    "commandStartedEvent"
                  ]
                }
              },
              {
                "database": {
                  "id": "database",
                  "client": "client",
                  "databaseName": "test"
                }
              },
              {
                "collection": {
                  "id": "collection",
                  "database": "database",
                  "collectionName": "coll"
                }
              },
              {
                "session": {
                  "id": "session",
                  "client": "client",
                  "sessionOptions": {
                    "defaultTransactionOptions": {
                      "maxCommitTimeMS": 1000
                    }
                  }
                }
              }
            ]
          }
        },
        {
          "name": "startTransaction",
          "object": "session"
        },
        {
          "name": "insertOne",
          "object": "collection",
          "arguments": {
            "document": {
              "_id": 1
            },
            "session": "session"
          }
        },
        {
          "name": "commitTransaction",
          "object": "session"
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "commandName": "insert",
                "databaseName": "test",
                "command": {
                  "insert": "coll",
                  "maxTimeMS": {
                    "$$exists": false
                  }
                }
              }
            },
            {
              "commandStartedEvent": {
                "commandName": "commitTransaction",
                "databaseName": "admin",
                "command": {
                  "commitTransaction": 1,
                  "maxTimeMS": 1000
                }
              }
            }
          ]
        }
      ]
    }
  ]
}
