{
  "description": "timeoutMS behaves correctly for GridFS delete operations",
  "schemaVersion": "1.9",
  "runOnRequirements": [
    {
      "minServerVersion": "4.4",
      "serverless": "forbid"
    }
  ],
  "createEntities": [
    {
      "client": {
        "id": "failPointClient",
        "useMultipleMongoses": false
      }
    },
    {
      "client": {
        "id": "client",
        "uriOptions": {
          "timeoutMS": 75
        },
        "useMultipleMongoses": false,
        "observeEvents": [
          "commandStartedEvent"
        ]
      }
    },
    {
      "database": {
        "id": "database",
        "client": "client",
        "databaseName": "test"
      }
    },
    {
      "bucket": {
        "id": "bucket",
        "database": "database"
      }
    },
    {
      "collection": {
        "id": "filesCollection",
        "database": "database",
        "collectionName": "fs.files"
      }
    },
    {
      "collection": {
        "id": "chunksCollection",
        "database": "database",
        "collectionName": "fs.chunks"
      }
    }
  ],
  "initialData": [
    {
      "collectionName": "fs.files",
      "databaseName": "test",
      "documents": [
        {
          "_id": {
            "$oid": "000000000000000000000005"
          },
          "length": 8,
          "chunkSize": 4,
          "uploadDate": {
            "$date": "1970-01-01T00:00:00.000Z"
          },
          "filename": "length-8",
          "contentType": "application/octet-stream",
          "aliases": [],
          "metadata": {}
        }
      ]
    },
    {
      "collectionName": "fs.chunks",
      "databaseName": "test",
      "documents": [
        {
          "_id": {
            "$oid": "000000000000000000000005"
          },
          "files_id": {
            "$oid": "000000000000000000000005"
          },
          "n": 0,
          "data": {
            "$binary": {
              "base64": "ESIzRA==",
              "subType": "00"
            }
          }
        },
        {
          "_id": {
            "$oid": "000000000000000000000006"
          },
          "files_id": {
            "$oid": "000000000000000000000005"
          },
          "n": 1,
          "data": {
            "$binary": {
              "base64": "ESIzRA==",
              "subType": "00"
            }
          }
        }
      ]
    }
  ],
  "tests": [
    {
      "description": "timeoutMS can be overridden for delete",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "failPointClient",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "delete"
                ],
                "blockConnection": true,
                "blockTimeMS": 100
              }
            }
          }
        },
        {
          "name": "delete",
          "object": "bucket",
          "arguments": {
            "id": {
              "$oid": "000000000000000000000005"
            },
            "timeoutMS": 1000
          }
        }
      ]
    },
    {
      "description": "timeoutMS applied to delete against the files collection",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "failPointClient",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "delete"
                ],
                "blockConnection": true,
                "blockTimeMS": 100
              }
            }
          }
        },
        {
          "name": "delete",
          "object": "bucket",
          "arguments": {
            "id": {
              "$oid": "000000000000000000000005"
            }
          },
          "expectError": {
            "isTimeoutError": true
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client",
          "events": [
            {
              "commandStartedEvent": {
                "commandName": "delete",
                "databaseName": "test",
                "command": {
                  "delete": "fs.files",
                  "maxTimeMS": {
                    "$$type": [
                      "int",
                      "long"
                    ]
                  }
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "timeoutMS applied to delete against the chunks collection",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "failPointClient",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "skip": 1
              },
              "data": {
                "failCommands": [
                  "delete"
                ],
                "blockConnection": true,
                "blockTimeMS": 100
              }
            }
          }
        },
        {
          "name": "delete",
          "object": "bucket",
          "arguments": {
            "id": {
              "$oid": "000000000000000000000005"
            }
          },
          "expectError": {
            "isTimeoutError": true
          }
        }
      ]
    },
    {
      "description": "timeoutMS applied to entire delete, not individual parts",
      "operations": [
        {
          "name": "failPoint",
          "object": "testRunner",
          "arguments": {
            "client": "failPointClient",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "delete"
                ],
                "blockConnection": true,
                "blockTimeMS": 50
              }
            }
          }
        },
        {
          "name": "delete",
          "object": "bucket",
          "arguments": {
            "id": {
              "$oid": "000000000000000000000005"
            }
          },
          "expectError": {
            "isTimeoutError": true
          }
        }
      ]
    }
  ]
}
