{
  "description": "distinct",
  "schemaVersion": "1.9",
  "runOnRequirements": [
    {
      "minServerVersion": "4.0",
      "topologies": [
        "single",
        "replicaset"
      ]
    },
    {
      "minServerVersion": "4.1.7",
      "topologies": [
        "sharded",
        "load-balanced"
      ]
    }
  ],
  "createEntities": [
    {
      "client": {
        "id": "client0",
        "useMultipleMongoses": false,
        "observeEvents": [
          "commandStartedEvent"
        ]
      }
    },
    {
      "database": {
        "id": "database0",
        "client": "client0",
        "databaseName": "retryable-reads-tests"
      }
    },
    {
      "collection": {
        "id": "collection0",
        "database": "database0",
        "collectionName": "coll"
      }
    }
  ],
  "initialData": [
    {
      "collectionName": "coll",
      "databaseName": "retryable-reads-tests",
      "documents": [
        {
          "_id": 1,
          "x": 11
        },
        {
          "_id": 2,
          "x": 22
        },
        {
          "_id": 3,
          "x": 33
        }
      ]
    }
  ],
  "tests": [
    {
      "description": "Distinct succeeds on first attempt",
      "operations": [
        {
          "object": "collection0",
          "name": "distinct",
          "arguments": {
            "fieldName": "x",
            "filter": {
              "_id": {
                "$gt": 1
              }
            }
          },
          "expectResult": [
            22,
            33
          ]
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "distinct": "coll",
                  "key": "x",
                  "query": {
                    "_id": {
                      "$gt": 1
                    }
                  }
                },
                "databaseName": "retryable-reads-tests"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "Distinct succeeds on second attempt",
      "operations": [
        {
          "object": "testRunner",
          "name": "failPoint",
          "arguments": {
            "client": "client0",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "distinct"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "object": "collection0",
          "name": "distinct",
          "arguments": {
            "fieldName": "x",
            "filter": {
              "_id": {
                "$gt": 1
              }
            }
          },
          "expectResult": [
            22,
            33
          ]
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "distinct": "coll",
                  "key": "x",
                  "query": {
                    "_id": {
                      "$gt": 1
                    }
                  }
                },
                "databaseName": "retryable-reads-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "distinct": "coll",
                  "key": "x",
                  "query": {
                    "_id": {
                      "$gt": 1
                    }
                  }
                },
                "databaseName": "retryable-reads-tests"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "Distinct fails on first attempt",
      "operations": [
        {
          "object": "testRunner",
          "name": "createEntities",
          "arguments": {
            "entities": [
              {
                "client": {
                  "id": "client1",
                  "useMultipleMongoses": false,
                  "uriOptions": {
                    "retryReads": false
                  },
                  "observeEvents": [
                    "commandStartedEvent"
                  ]
                }
              },
              {
                "database": {
                  "id": "database1",
                  "client": "client1",
                  "databaseName": "retryable-reads-tests"
                }
              },
              {
                "collection": {
                  "id": "collection1",
                  "database": "database1",
                  "collectionName": "coll"
                }
              }
            ]
          }
        },
        {
          "object": "testRunner",
          "name": "failPoint",
          "arguments": {
            "client": "client1",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 1
              },
              "data": {
                "failCommands": [
                  "distinct"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "object": "collection1",
          "name": "distinct",
          "arguments": {
            "fieldName": "x",
            "filter": {
              "_id": {
                "$gt": 1
              }
            }
          },
          "expectError": {
            "isError": true
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client1",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "distinct": "coll",
                  "key": "x",
                  "query": {
                    "_id": {
                      "$gt": 1
                    }
                  }
                },
                "databaseName": "retryable-reads-tests"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "Distinct fails on second attempt",
      "operations": [
        {
          "object": "testRunner",
          "name": "failPoint",
          "arguments": {
            "client": "client0",
            "failPoint": {
              "configureFailPoint": "failCommand",
              "mode": {
                "times": 2
              },
              "data": {
                "failCommands": [
                  "distinct"
                ],
                "closeConnection": true
              }
            }
          }
        },
        {
          "object": "collection0",
          "name": "distinct",
          "arguments": {
            "fieldName": "x",
            "filter": {
              "_id": {
                "$gt": 1
              }
            }
          },
          "expectError": {
            "isError": true
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "distinct": "coll",
                  "key": "x",
                  "query": {
                    "_id": {
                      "$gt": 1
                    }
                  }
                },
                "databaseName": "retryable-reads-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "distinct": "coll",
                  "key": "x",
                  "query": {
                    "_id": {
                      "$gt": 1
                    }
                  }
                },
                "databaseName": "retryable-reads-tests"
              }
            }
          ]
        }
      ]
    }
  ]
}
