From a54816b8cd2cc9921909e85a4e09c76453630de4 Mon Sep 17 00:00:00 2001 From: Pete Woods Date: Mon, 8 Apr 2024 13:38:23 +0100 Subject: [PATCH 1/2] Bootstrap GHA --- .github/workflows/go.yml | 103 +++++++++++++++++++++++++++++++++ mysqlstore/testdata/schema.sql | 7 +++ pgxstore/testdata/schema.sql | 7 +++ 3 files changed, 117 insertions(+) create mode 100644 .github/workflows/go.yml create mode 100644 mysqlstore/testdata/schema.sql create mode 100644 pgxstore/testdata/schema.sql diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..f4907f7 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,103 @@ +name: Go + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + test: + runs-on: ubuntu-latest + + services: + + mysql: + image: mysql + env: + MYSQL_ROOT_PASSWORD: root-password + MYSQL_DATABASE: dbname + MYSQL_USER: user + MYSQL_PASSWORD: password + options: >- + --health-cmd "mysqladmin ping --silent" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 3306:3306 + + postgres: + image: postgres + env: + POSTGRES_DB: dbname + POSTGRES_USER: user + POSTGRES_PASSWORD: password + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 6379:6379 + + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.20' + + - name: Test + run: go test -race -v ./... + + - name: Run postgres migrations + run: psql -f pgxstore/testdata/schema.sql postgres://user:password@localhost:5432/dbname + + - name: Run mysql migrations + run: mysql --protocol=TCP --host=localhost --port=3306 --user=user --password=password dbname < mysqlstore/testdata/schema.sql + + - name: Test goredisstore + env: + SCS_REDIS_TEST_DSN: redis://localhost:6379 + working-directory: goredisstore + run: go test -race -v ./... + + - name: Test mysqlstore + env: + SCS_MYSQL_TEST_DSN: user:password@tcp(localhost:3306)/dbname + working-directory: mysqlstore + run: go test -race -v ./... + + - name: Test pgxstore + env: + SCS_POSTGRES_TEST_DSN: postgres://user:password@localhost:5432/dbname + working-directory: pgxstore + run: go test -race -v ./... + + - name: Test postgresstore + env: + SCS_POSTGRES_TEST_DSN: postgres://user:password@localhost:5432/dbname?sslmode=disable + working-directory: postgresstore + run: go test -race -v ./... + + - name: Test redisstore + env: + SCS_REDIS_TEST_DSN: localhost:6379 + working-directory: redisstore + run: go test -race -v ./... + + - name: Test sqlite3store + working-directory: sqlite3store + run: go test -race -v ./... diff --git a/mysqlstore/testdata/schema.sql b/mysqlstore/testdata/schema.sql new file mode 100644 index 0000000..ba74911 --- /dev/null +++ b/mysqlstore/testdata/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE sessions ( + token CHAR(43) PRIMARY KEY, + data BLOB NOT NULL, + expiry TIMESTAMP(6) NOT NULL +); + +CREATE INDEX sessions_expiry_idx ON sessions (expiry); \ No newline at end of file diff --git a/pgxstore/testdata/schema.sql b/pgxstore/testdata/schema.sql new file mode 100644 index 0000000..0d5fcd3 --- /dev/null +++ b/pgxstore/testdata/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE sessions ( + token TEXT PRIMARY KEY, + data BYTEA NOT NULL, + expiry TIMESTAMPTZ NOT NULL +); + +CREATE INDEX sessions_expiry_idx ON sessions (expiry); From 452f3b77b2f367e17a3751acaea3c9abc5215825 Mon Sep 17 00:00:00 2001 From: Pete Steyert-Woods Date: Tue, 9 Apr 2024 13:05:58 +0100 Subject: [PATCH 2/2] Fix race condition in test --- memstore/memstore_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/memstore/memstore_test.go b/memstore/memstore_test.go index 4b96289..52ecb75 100644 --- a/memstore/memstore_test.go +++ b/memstore/memstore_test.go @@ -111,15 +111,21 @@ func TestDelete(t *testing.T) { func TestCleanupInterval(t *testing.T) { m := NewWithCleanupInterval(100 * time.Millisecond) defer m.StopCleanup() + m.mu.Lock() m.items["session_token"] = item{object: []byte("encoded_data"), expiration: time.Now().Add(500 * time.Millisecond).UnixNano()} + m.mu.Unlock() + m.mu.Lock() _, ok := m.items["session_token"] + m.mu.Unlock() if !ok { t.Fatalf("got %v: expected %v", ok, true) } time.Sleep(time.Second) + m.mu.Lock() _, ok = m.items["session_token"] + m.mu.Unlock() if ok { t.Fatalf("got %v: expected %v", ok, false) }