# The nightly-gauntlet runs tests that are either too flaky or too slow to block
# every PR.
name: nightly-gauntlet
on:
  schedule:
    # Every day at midnight
    - cron: "0 0 * * *"
  workflow_dispatch:
jobs:
  go-race:
    # While GitHub's toaster runners are likelier to flake, we want consistency
    # between this environment and the regular test environment for DataDog
    # statistics and to only show real workflow threats.
    runs-on: "buildjet-8vcpu-ubuntu-2204"
    # This runner costs 0.016 USD per minute,
    # so 0.016 * 240 = 3.84 USD per run.
    timeout-minutes: 240
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup Go
        uses: ./.github/actions/setup-go

      - name: Setup Terraform
        uses: ./.github/actions/setup-tf

      - name: Run Tests
        run: |
          # -race is likeliest to catch flaky tests
          # due to correctness detection and its performance
          # impact.
          gotestsum --junitfile="gotests.xml" -- -timeout=240m -count=10 -race ./...

      - name: Upload test results to DataDog
        uses: ./.github/actions/upload-datadog
        if: always()
        with:
          api-key: ${{ secrets.DATADOG_API_KEY }}

  go-timing:
    # We run these tests with p=1 so we don't need a lot of compute.
    runs-on: "buildjet-2vcpu-ubuntu-2204"
    timeout-minutes: 10
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Setup Go
        uses: ./.github/actions/setup-go

      - name: Run Tests
        run: |
          gotestsum --junitfile="gotests.xml" -- --tags="timing" -p=1 -run='_Timing/' ./...

      - name: Upload test results to DataDog
        uses: ./.github/actions/upload-datadog
        if: always()
        with:
          api-key: ${{ secrets.DATADOG_API_KEY }}
