Skip to content

Commit

Permalink
Add GitHub workflow for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jace-ys committed Mar 1, 2021
1 parent a50ff06 commit c3088eb
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 3 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: ci

on: push

jobs:
check:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
./target
key: ${{ runner.os }}-redlock-rs-${{ hashFiles('Cargo.toml') }}
restore-keys: ${{ runner.os }}-redlock-rs-
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check

fmt:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
./target
key: ${{ runner.os }}-redlock-rs-${{ hashFiles('Cargo.toml') }}
restore-keys: ${{ runner.os }}-redlock-rs-
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
./target
key: ${{ runner.os }}-redlock-rs-${{ hashFiles('Cargo.toml') }}
restore-keys: ${{ runner.os }}-redlock-rs-
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
./target
key: ${{ runner.os }}-redlock-rs-${{ hashFiles('Cargo.toml') }}
restore-keys: ${{ runner.os }}-redlock-rs-
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: docker-compose up -d
- uses: actions-rs/cargo@v1
with:
command: test
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[![ci-badge]][ci-workflow]

[ci-badge]: https://github.com/jace-ys/redlock-rs/workflows/ci/badge.svg
[ci-workflow]: https://github.com/jace-ys/redlock-rs/actions?query=workflow%3Aci

# `redlock-rs`

A Rust implementation of [Redlock](https://redis.io/topics/distlock) for distributed locks with Redis.
6 changes: 3 additions & 3 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod tests {
let lock = Lock {
resource: String::from(resource),
value: String::from("1"),
ttl: Duration::from_millis(100),
ttl: Duration::from_millis(500),
expiry: Instant::now(),
};

Expand Down Expand Up @@ -180,7 +180,7 @@ mod tests {
fn extend_expired_lock() -> Result<(), RedlockError> {
let test = setup("extend_expired_lock");
test.instance.acquire(&test.lock)?;
thread::sleep(Duration::from_millis(100));
thread::sleep(Duration::from_secs(1));

let attempt = test.instance.extend(&test.lock);
assert!(matches!(attempt, Err(RedlockError::InvalidLease)));
Expand Down Expand Up @@ -215,7 +215,7 @@ mod tests {
fn release_expired_lock() -> Result<(), RedlockError> {
let test = setup("unlock_expired_lock");
test.instance.acquire(&test.lock)?;
thread::sleep(Duration::from_millis(100));
thread::sleep(Duration::from_secs(1));

let attempt = test.instance.release(&test.lock);
assert!(matches!(attempt, Err(RedlockError::InvalidLease)));
Expand Down

0 comments on commit c3088eb

Please sign in to comment.