Skip to content
Merged
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
34 changes: 10 additions & 24 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,19 @@ on:
jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy
- name: Install dependencies
run: sudo apt-get install libevent-dev libssl-dev
- name: Setup memcached
components: rustfmt
- uses: Swatinem/rust-cache@v2
- name: Start memcached servers
run: ./tests/setup_tests.sh
env:
MEMCACHED_IMAGE: memcached:1.6.45-alpine
- name: Check format
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
run: cargo fmt --all -- --check
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
run: cargo build
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features -- --test-threads=1
run: cargo test --all-features -- --test-threads=1
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ Cargo.lock
*.dSYM
target/

tests/memcached-*/
5 changes: 4 additions & 1 deletion src/exp/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub struct Get {
pub no_lru_bump: bool,
/// Suppress the value when the item CAS still matches; the result status
/// becomes [`Unchanged`](super::GetStatus::Unchanged). Requires `value`.
/// Needs memcached 1.6.40 or newer; older servers ignore the flag and
/// return the value.
pub unless_cas: Option<u64>,
/// Whether to read the value at all; `false` fetches metadata only.
pub value: bool,
Expand Down Expand Up @@ -140,7 +142,8 @@ impl Get {
self
}

/// Suppress the value when the item CAS still matches.
/// Suppress the value when the item CAS still matches. Needs memcached
/// 1.6.40 or newer; older servers ignore the flag and return the value.
#[must_use]
pub fn unless_cas(mut self, cas: u64) -> Get {
self.unless_cas = Some(cas);
Expand Down
3 changes: 2 additions & 1 deletion src/exp/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ impl<'a, C> Request<'a, C, Get> {
self
}

/// Suppress the value when the item CAS still matches.
/// Suppress the value when the item CAS still matches. Needs memcached
/// 1.6.40 or newer; older servers ignore the flag and return the value.
pub fn unless_cas(mut self, cas: u64) -> Self {
self.operation = self.operation.unless_cas(cas);
self
Expand Down
69 changes: 39 additions & 30 deletions tests/setup_tests.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
#!/bin/bash
# Starts the memcached instances the integration tests expect.
#
# By default this runs the memcached binary on PATH, which must be built with
# TLS support (the Debian, Ubuntu and Arch packages qualify) and be 1.6.40 or
# newer, the release that added the conditional meta get used by unless_cas.
# Set MEMCACHED to point at another binary, or set MEMCACHED_IMAGE to run each
# instance from the official Docker image on the host network instead, which
# is what CI does because the Ubuntu package is too old.
set -e

BASEDIR=$(dirname "$0")
MEMCACHED_VERSION="1.6.45"
MEMCACHED_TARBALL="memcached-$MEMCACHED_VERSION.tar.gz"
MEMCACHED_DIR="$BASEDIR/memcached-$MEMCACHED_VERSION"
MEMCACHED="$MEMCACHED_DIR/memcached"
ASSETS=$(realpath "$(dirname "$0")/assets")
MEMCACHED="${MEMCACHED:-memcached}"

SSL_KEY=$BASEDIR/assets/localhost.key
SSL_CERT=$BASEDIR/assets/localhost.crt
SSL_ROOT_CERT=$BASEDIR/assets/RUST_MEMCACHE_TEST_CERT.crt
SSL_KEY=$ASSETS/localhost.key
SSL_CERT=$ASSETS/localhost.crt
SSL_ROOT_CERT=$ASSETS/RUST_MEMCACHE_TEST_CERT.crt

echo "Building memcached $MEMCACHED_VERSION with TLS support"
if [[ ! -d "$MEMCACHED_DIR" ]]; then
curl "https://memcached.org/files/$MEMCACHED_TARBALL" -O
tar xvf "$MEMCACHED_TARBALL" -C "$BASEDIR"
rm "$MEMCACHED_TARBALL"
fi
start() {
if [[ -n "$MEMCACHED_IMAGE" ]]; then
docker run -d --rm --network host -v /tmp:/tmp -v "$ASSETS:$ASSETS:ro" \
"$MEMCACHED_IMAGE" "$@" > /dev/null
else
"$MEMCACHED" "$@" -d
fi
}

if [[ ! -f "$MEMCACHED" ]]; then
pushd "$MEMCACHED_DIR"
./configure --enable-tls
make
popd
if [[ -n "$MEMCACHED_IMAGE" ]]; then
docker run --rm "$MEMCACHED_IMAGE" -V
else
if ! "$MEMCACHED" -h 2>&1 | grep -q -- '--enable-ssl'; then
echo "error: $MEMCACHED was built without TLS support" >&2
exit 1
fi
"$MEMCACHED" -V
fi

echo "Starting memcached servers"
$MEMCACHED -V
$MEMCACHED -p 12345 -d
$MEMCACHED -p 12346 -d
$MEMCACHED -p 12347 -d
$MEMCACHED -p 12348 -d
$MEMCACHED -p 12349 -d
$MEMCACHED -p 12350 -d --enable-ssl -o "ssl_key=$SSL_KEY,ssl_chain_cert=$SSL_CERT"
$MEMCACHED -p 12351 -d --enable-ssl -o "ssl_key=$SSL_KEY,ssl_chain_cert=$SSL_CERT,ssl_verify_mode=2,ssl_ca_cert=$SSL_ROOT_CERT"
$MEMCACHED -U 22345 -d
$MEMCACHED -s /tmp/memcached.sock -d
$MEMCACHED -s /tmp/memcached2.sock -d
start -p 12345
start -p 12346
start -p 12347
start -p 12348
start -p 12349
start -p 12350 --enable-ssl -o "ssl_key=$SSL_KEY,ssl_chain_cert=$SSL_CERT"
start -p 12351 --enable-ssl -o "ssl_key=$SSL_KEY,ssl_chain_cert=$SSL_CERT,ssl_verify_mode=2,ssl_ca_cert=$SSL_ROOT_CERT"
start -U 22345
start -s /tmp/memcached.sock -a 777
start -s /tmp/memcached2.sock -a 777
Loading