tests:
- name: users and grants cannot be run on standby
  multi_repos:
  - name: server1
    with_files:
    - name: server.yaml
      contents: |
        log_level: trace
        listener:
          host: 0.0.0.0
          port: 3309
        cluster:
          standby_remotes:
          - name: standby
            remote_url_template: http://localhost:3852/{database}
          bootstrap_role: primary
          bootstrap_epoch: 1
          remotesapi:
            port: 3851
    server:
      args: ["--config", "server.yaml"]
      port: 3309
  - name: server2
    with_files:
    - name: server.yaml
      contents: |
        log_level: trace
        listener:
          host: 0.0.0.0
          port: 3310
        cluster:
          standby_remotes:
          - name: standby
            remote_url_template: http://localhost:3851/{database}
          bootstrap_role: standby
          bootstrap_epoch: 1
          remotesapi:
            port: 3852
    server:
      args: ["--config", "server.yaml"]
      port: 3310
  connections:
  - on: server2
    queries:
    - exec: 'CREATE USER "brian"@"%" IDENTIFIED BY "brianspassword"'
      error_match: 'database server is set to read only mode'
    - exec: 'GRANT ALL ON *.* TO "aaron"@"%"'
      error_match: 'database server is set to read only mode'
- name: create database cannot be run on standby
  multi_repos:
  - name: server1
    with_files:
    - name: server.yaml
      contents: |
        log_level: trace
        listener:
          host: 0.0.0.0
          port: 3309
        cluster:
          standby_remotes:
          - name: standby
            remote_url_template: http://localhost:3852/{database}
          bootstrap_role: primary
          bootstrap_epoch: 1
          remotesapi:
            port: 3851
    server:
      args: ["--config", "server.yaml"]
      port: 3309
  - name: server2
    with_files:
    - name: server.yaml
      contents: |
        log_level: trace
        listener:
          host: 0.0.0.0
          port: 3310
        cluster:
          standby_remotes:
          - name: standby
            remote_url_template: http://localhost:3851/{database}
          bootstrap_role: standby
          bootstrap_epoch: 1
          remotesapi:
            port: 3852
    server:
      args: ["--config", "server.yaml"]
      port: 3310
  connections:
  - on: server2
    queries:
    - exec: 'CREATE DATABASE my_db'
      error_match: 'database server is set to read only mode'
- name: drop database cannot be run on standby
  multi_repos:
  - name: server1
    with_files:
    - name: server.yaml
      contents: |
        log_level: trace
        listener:
          host: 0.0.0.0
          port: 3309
        cluster:
          standby_remotes:
          - name: standby
            remote_url_template: http://localhost:3852/{database}
          bootstrap_role: primary
          bootstrap_epoch: 1
          remotesapi:
            port: 3851
    server:
      args: ["--config", "server.yaml"]
      port: 3309
  - name: server2
    with_files:
    - name: server.yaml
      contents: |
        log_level: trace
        listener:
          host: 0.0.0.0
          port: 3310
        cluster:
          standby_remotes:
          - name: standby
            remote_url_template: http://localhost:3851/{database}
          bootstrap_role: standby
          bootstrap_epoch: 1
          remotesapi:
            port: 3852
    server:
      args: ["--config", "server.yaml"]
      port: 3310
  connections:
  - on: server1
    queries:
    - exec: 'SET @@PERSIST.dolt_cluster_ack_writes_timeout_secs = 10'
    - exec: 'CREATE DATABASE repo1'
    - exec: 'USE repo1'
    - exec: 'CREATE TABLE vals (i INT PRIMARY KEY)'
    - exec: 'INSERT INTO vals VALUES (0),(1),(2),(3),(4)'
  - on: server2
    queries:
    - exec: 'DROP DATABASE repo1'
      error_match: 'database server is set to read only mode'
- name: when a server becomes primary it accepts writes
  multi_repos:
  - name: server1
    with_files:
    - name: server.yaml
      contents: |
        log_level: trace
        listener:
          host: 0.0.0.0
          port: 3309
        cluster:
          standby_remotes:
          - name: standby
            remote_url_template: http://localhost:3852/{database}
          bootstrap_role: primary
          bootstrap_epoch: 1
          remotesapi:
            port: 3851
    server:
      args: ["--config", "server.yaml"]
      port: 3309
  - name: server2
    with_files:
    - name: server.yaml
      contents: |
        log_level: trace
        listener:
          host: 0.0.0.0
          port: 3310
        cluster:
          standby_remotes:
          - name: standby
            remote_url_template: http://localhost:3851/{database}
          bootstrap_role: standby
          bootstrap_epoch: 1
          remotesapi:
            port: 3852
    server:
      args: ["--config", "server.yaml"]
      port: 3310
  connections:
  - on: server2
    queries:
    - exec: 'CALL DOLT_ASSUME_CLUSTER_ROLE("primary", 2)'
  - on: server2
    queries:
    - exec: 'SET @@PERSIST.dolt_cluster_ack_writes_timeout_secs = 10'
    - exec: 'CREATE DATABASE repo1'
    - exec: 'USE repo1'
    - exec: 'CREATE TABLE vals (i INT PRIMARY KEY)'
    - exec: 'INSERT INTO vals VALUES (0),(1),(2),(3),(4)'
  - on: server1
    queries:
    - exec: 'USE repo1'
    - query: 'SELECT COUNT(*) FROM vals'
      result:
        columns: ["COUNT(*)"]
        rows:
        - [5]
