Skip to content

Commit

Permalink
Run cargo tests on all platforms (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
arriqaaq authored Jan 23, 2025
1 parent bc9bf80 commit e782ed2
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 102 deletions.
75 changes: 40 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,34 @@ defaults:
shell: bash

jobs:
build:
runs-on: ubuntu-latest
build-test:
strategy:
matrix:
target: [ 'x86_64-unknown-linux-gnu', 'aarch64-unknown-linux-gnu', 'x86_64-pc-windows-msvc', 'x86_64-apple-darwin', 'aarch64-apple-darwin', 'wasm32-unknown-unknown' ]
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: wasm32-unknown-unknown
os: ubuntu-latest

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Cache
id: rust-cache
uses: actions/cache@v3
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup cache
uses: Swatinem/rust-cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml', '.github/workflows/*.yml') }}
save-if: ${{ github.ref == 'refs/heads/main' }}

- uses: actions-rs/toolchain@v1
with:
Expand All @@ -40,32 +50,27 @@ jobs:
components: rustfmt, clippy
default: true

- name: Compile
- name: Build
run: cargo build --target=${{ matrix.target }}

ci:
strategy:
matrix:
os: ["ubuntu-latest"]

runs-on: ${{ matrix.os }}
- name: Run tests
if: ${{ !contains(matrix.os, 'windows') }}
# Skip tests on Windows as compaction tests are not supported
run: make test

ci:
runs-on: ubuntu-latest
env:
RUSTFLAGS: --deny warnings

steps:
- uses: actions/checkout@v2
- name: Cache
id: rust-cache
uses: actions/cache@v3
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup cache
uses: Swatinem/rust-cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml', '.github/workflows/*.yml') }}
save-if: ${{ github.ref == 'refs/heads/main' }}

- uses: actions-rs/toolchain@v1
with:
Expand All @@ -74,13 +79,13 @@ jobs:
default: true

- name: Install cargo-deny
run: cargo install --debug --locked [email protected]
run: which cargo-deny || cargo install --debug --locked [email protected]

- name: Run tests
run: make test
- name: License check
run: cargo deny --all-features check licenses

- name: Clippy
run: cargo clippy --all --all-targets -- -Dwarnings

- name: Format
run: cargo fmt --all -- --check
run: cargo fmt --all -- --check
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ check:
cargo clippy --all --all-targets

# This command runs the tests with backtrace enabled.
test: check
test:
RUST_BACKTRACE=1 cargo test

.PHONY: build-cli
Expand Down
66 changes: 66 additions & 0 deletions src/compaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,4 +1499,70 @@ mod tests {
// Close the store
store.close().unwrap();
}

#[test]
fn compaction_preserves_key_deletion() {
// Create a temporary directory for testing
let temp_dir = create_temp_directory();

// Create store options with the test directory
let mut opts = Options::new();
opts.dir = temp_dir.path().to_path_buf();
opts.max_value_threshold = 0;
opts.max_value_cache_size = 0;

// Create a new store instance with VariableKey as the key type
let store = Store::new(opts.clone()).expect("should create store");

// Number of keys to generate and write
let num_keys_to_write = 1;

// Create a vector to store the generated keys
let mut keys: Vec<Bytes> = Vec::new();

for counter in 1usize..=num_keys_to_write {
// Convert the counter to Bytes
let key_bytes = Bytes::from(counter.to_le_bytes().to_vec());

// Add the key to the vector
keys.push(key_bytes);
}

let default_value = Bytes::from("default_value".to_string());
let default_value2 = Bytes::from("default_value2".to_string());

// Write the keys to the store
for key in keys.iter() {
let mut txn = store.begin().unwrap();
txn.set(key, &default_value).unwrap();
txn.commit().unwrap();
}

for key in keys.iter() {
let mut txn = store.begin().unwrap();
txn.set(key, &default_value2).unwrap();
txn.commit().unwrap();
}

let key_bytes = Bytes::from(2usize.to_le_bytes().to_vec());
let mut txn = store.begin().unwrap();
txn.set(&key_bytes, &default_value2).unwrap();
txn.commit().unwrap();

// Delete the first 5 keys from the store
for key in keys.iter() {
let mut txn = store.begin().unwrap();
txn.delete(key).unwrap();
txn.commit().unwrap();
}

store.compact().unwrap();
store.close().unwrap();

let reopened_store = Store::new(opts).expect("should reopen store");
for key in keys.iter() {
let mut txn = reopened_store.begin().unwrap();
assert!(txn.get(key).unwrap().is_none());
}
}
}
66 changes: 0 additions & 66 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,72 +1102,6 @@ mod tests {
}
}

#[test]
fn basic_compaction1() {
// Create a temporary directory for testing
let temp_dir = create_temp_directory();

// Create store options with the test directory
let mut opts = Options::new();
opts.dir = temp_dir.path().to_path_buf();
opts.max_value_threshold = 0;
opts.max_value_cache_size = 0;

// Create a new store instance with VariableKey as the key type
let store = Store::new(opts.clone()).expect("should create store");

// Number of keys to generate and write
let num_keys_to_write = 1;

// Create a vector to store the generated keys
let mut keys: Vec<Bytes> = Vec::new();

for counter in 1usize..=num_keys_to_write {
// Convert the counter to Bytes
let key_bytes = Bytes::from(counter.to_le_bytes().to_vec());

// Add the key to the vector
keys.push(key_bytes);
}

let default_value = Bytes::from("default_value".to_string());
let default_value2 = Bytes::from("default_value2".to_string());

// Write the keys to the store
for key in keys.iter() {
let mut txn = store.begin().unwrap();
txn.set(key, &default_value).unwrap();
txn.commit().unwrap();
}

for key in keys.iter() {
let mut txn = store.begin().unwrap();
txn.set(key, &default_value2).unwrap();
txn.commit().unwrap();
}

let key_bytes = Bytes::from(2usize.to_le_bytes().to_vec());
let mut txn = store.begin().unwrap();
txn.set(&key_bytes, &default_value2).unwrap();
txn.commit().unwrap();

// Delete the first 5 keys from the store
for key in keys.iter() {
let mut txn = store.begin().unwrap();
txn.delete(key).unwrap();
txn.commit().unwrap();
}

store.compact().unwrap();
store.close().unwrap();

let reopened_store = Store::new(opts).expect("should reopen store");
for key in keys.iter() {
let mut txn = reopened_store.begin().unwrap();
assert!(txn.get(key).unwrap().is_none());
}
}

#[test]
fn test_store_with_varying_segment_sizes() {
let temp_dir = create_temp_directory();
Expand Down

0 comments on commit e782ed2

Please sign in to comment.