Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/reusable-rust-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ on:
required: false
type: string
default: './run-tests.sh'
shard-count:
description: 'Total number of test shards'
required: false
type: number
default: 1
shard-indexes:
description: 'JSON array of shard indexes to run (e.g. [0,1])'
required: false
type: string
default: '[0]'
jobs:
test:
strategy:
matrix:
rust-version: ${{ fromJSON(inputs.rust-versions) }}
platform: ${{ fromJSON(inputs.platforms) }}
shard-index: ${{ fromJSON(inputs.shard-indexes) }}
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
Expand All @@ -49,4 +60,7 @@ jobs:
key: ${{ runner.os }}-cargo-${{ matrix.rust-version }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-${{ matrix.rust-version }}-
- name: Test
run: ${{ inputs.test-script }}
run: ${{ inputs.test-script }}
env:
TEST_SHARD_TOTAL: ${{ inputs.shard-count }}
TEST_SHARD_INDEX: ${{ matrix.shard-index }}
67 changes: 62 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,74 @@ jobs:
with:
enable-commit-changes: true

build:
if: >
(github.event.pull_request.draft == false &&
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
github.event_name == 'schedule'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: DataDog/datadog-api-client-rust
- name: Install Rust
run: rustup toolchain install stable --profile minimal --no-self-update && rustup default stable
shell: bash
- name: Cache Cargo
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-stable-${{ hashFiles('**/Cargo.toml') }}
restore-keys: ${{ runner.os }}-cargo-stable-
- name: Compile test binary
run: cargo test --test main --no-run
shell: bash
- name: License check
run: ./scripts/license-check.sh
shell: bash
- name: Stage test binary
shell: bash
run: |
BINARY=$(find target/debug/deps -name 'main-*' -executable -type f | head -1)
echo "Uploading binary: $BINARY"
cp "$BINARY" test-binary
- name: Upload test binary
uses: actions/upload-artifact@v4
with:
name: test-binary
path: test-binary
retention-days: 1

test:
if: >
(github.event.pull_request.draft == false &&
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
github.event_name == 'schedule'
uses: ./.github/workflows/reusable-rust-test.yml
with:
rust-versions: '["stable"]'
platforms: '["ubuntu-latest"]'
test-script: './run-tests.sh'
needs: build
strategy:
matrix:
shard: [0, 1, 2, 3]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: DataDog/datadog-api-client-rust
- name: Download test binary
uses: actions/download-artifact@v4
with:
name: test-binary
- name: Run test shard
shell: bash
run: |
chmod +x test-binary
TEST_SHARD_TOTAL=4 TEST_SHARD_INDEX=${{ matrix.shard }} ./test-binary

examples:
if: >
Expand Down
14 changes: 14 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ async fn main() {
.unwrap_or("false".to_string())
.to_lowercase();
let is_replay = !record_mode.eq("true") && !record_mode.eq("none");
let shard_total: usize = env::var("TEST_SHARD_TOTAL")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(1);
let shard_index: usize = env::var("TEST_SHARD_INDEX")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(0);
let concurrent_scenarios = match is_replay {
true => 64,
false => 1,
Expand Down Expand Up @@ -105,6 +113,12 @@ async fn main() {
false
} else if is_replay && sc.tags.contains(&"integration-only".into()) {
false
} else if shard_total > 1 {
// FNV-1a: stable across Rust versions, better avalanche than byte-sum
let hash = sc.name.bytes().fold(2166136261u32, |acc, b| {
(acc ^ b as u32).wrapping_mul(16777619)
});
(hash as usize) % shard_total == shard_index
} else {
true
}
Expand Down
Loading