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
26 changes: 26 additions & 0 deletions .github/workflows/jepsen-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on: [ push ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-jepsen-test

name: Jepsen Test
jobs:
test:
runs-on: ubuntu-latest
env:
RUN_JEPSEN: 'true'
steps:
- uses: actions/checkout@v5
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- name: Install Leiningen
run: |
curl -L https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > ~/lein
chmod +x ~/lein
~/lein version
- name: Run Jepsen tests
if: env.RUN_JEPSEN == 'true'
working-directory: jepsen
run: ~/lein test
Comment on lines +9 to +26

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 4 months ago

To fix the issue, add a permissions block specifying the minimum required permissions for the workflow. The best practice is to set contents: read at either the workflow root or per-job basis. For this workflow, since the job does not require write permissions (no deployment, repository pushing, etc.), we can safely set contents: read at the workflow root. This will limit the GITHUB_TOKEN permissions for all jobs that do not declare their own overrides. Edit .github/workflows/jepsen-test.yml by inserting the following after the name: block and before jobs: on line 7:

permissions:
  contents: read

This ensures the workflow runs with the principle of least privilege.

Suggested changeset 1
.github/workflows/jepsen-test.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/jepsen-test.yml b/.github/workflows/jepsen-test.yml
--- a/.github/workflows/jepsen-test.yml
+++ b/.github/workflows/jepsen-test.yml
@@ -4,6 +4,8 @@
   group: ${{ github.workflow }}-${{ github.ref }}-jepsen-test
 
 name: Jepsen Test
+permissions:
+  contents: read
 jobs:
   test:
     runs-on: ubuntu-latest
EOF
@@ -4,6 +4,8 @@
group: ${{ github.workflow }}-${{ github.ref }}-jepsen-test

name: Jepsen Test
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
Copilot is powered by AI and may make mistakes. Always verify output.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@
go.work

# Built binary
elastickv
/elastickv

# Clojure/Leiningen build artifacts
jepsen/target/
jepsen/.lein-*
jepsen/.nrepl-port
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ quit

### Development

### Running Jepsen tests

Jepsen tests live in `jepsen/`. Install Leiningen and run tests locally:

```bash
curl -L https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > ~/lein
chmod +x ~/lein
(cd jepsen && ~/lein test)
```

These Jepsen tests execute concurrent read and write operations while a nemesis
injects random network partitions. Jepsen's linearizability checker verifies the
history.



### Setup pre-commit hooks
```bash
Expand Down
8 changes: 8 additions & 0 deletions jepsen/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(defproject elastickv-jepsen "0.1.0-SNAPSHOT"
:description "Jepsen tests for Elastickv"
:repositories [["clojars" {:url "https://repo.clojars.org"}]]
:dependencies [[org.clojure/clojure "1.11.1"]
[jepsen "0.3.5"]
[redis.clients/jedis "5.1.0" :exclusions [org.slf4j/slf4j-api]]
[org.slf4j/slf4j-nop "2.0.9"]]
:main elastickv.jepsen-test)
45 changes: 45 additions & 0 deletions jepsen/src/elastickv/jepsen_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(ns elastickv.jepsen-test
(:gen-class)
(:require [jepsen
[core :as jepsen]
[cli :as cli]
[db :as db]
[client :as client]
[checker :as checker]]
[jepsen.checker.timeline :as timeline]
[jepsen.tests.linearizable-register :as register]
[jepsen.nemesis :as nemesis])
(:import (redis.clients.jedis Jedis)))

(defrecord RedisClient [port]
client/Client
(open! [this test node]
(assoc this :conn (Jedis. (name node) port)))
(close! [this test]
(.close (:conn this))
this)
(setup! [this test])
(teardown! [this test])
(invoke! [this test op]
(let [conn (:conn this)
value (:value op)]
(case (:f op)
:write (do (.set conn "k" (pr-str value))
(assoc op :type :ok))
:read (let [v (.get conn "k")]
(assoc op :type :ok
:value (when v (read-string v))))
(assoc op :type :fail :error :unknown-op)))))

(defn elastickv-test []
(register/test
{:name "elastickv-register"
:nodes ["n1" "n2" "n3"]
:db db/noop
:client (->RedisClient 63791)
:concurrency 5
:nemesis (nemesis/partition-random-halves)}))

(defn -main
[& args]
(cli/run! (cli/single-test-cmd {:test-fn elastickv-test}) args))
6 changes: 6 additions & 0 deletions jepsen/test/elastickv/jepsen_test_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns elastickv.jepsen-test-test
(:require [clojure.test :refer :all]
[elastickv.jepsen-test :as jt]))

(deftest builds-test-spec
(is (map? (jt/elastickv-test))))
Loading