From 74d2c234d51567b6d4706ae29c1b595e4507e894 Mon Sep 17 00:00:00 2001 From: An Long Date: Tue, 8 Sep 2026 22:50:11 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Run=20memcached=20from=20the=20o?= =?UTF-8?q?fficial=20Docker=20image=20in=20CI=20and=20update=20the=20actio?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yaml | 34 ++++++------------- .gitignore | 1 - src/exp/operation.rs | 5 ++- src/exp/request.rs | 3 +- tests/setup_tests.sh | 69 ++++++++++++++++++++++----------------- 5 files changed, 55 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 348dc42..d8085f9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/.gitignore b/.gitignore index d0795fe..e154a23 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ Cargo.lock *.dSYM target/ -tests/memcached-*/ diff --git a/src/exp/operation.rs b/src/exp/operation.rs index f703cc1..914846b 100644 --- a/src/exp/operation.rs +++ b/src/exp/operation.rs @@ -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, /// Whether to read the value at all; `false` fetches metadata only. pub value: bool, @@ -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); diff --git a/src/exp/request.rs b/src/exp/request.rs index 219d054..cbf5632 100644 --- a/src/exp/request.rs +++ b/src/exp/request.rs @@ -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 diff --git a/tests/setup_tests.sh b/tests/setup_tests.sh index d7485ad..4f5a4b8 100755 --- a/tests/setup_tests.sh +++ b/tests/setup_tests.sh @@ -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