Skip to content

Commit

Permalink
Setup CI with GitHub Actions Workflow (#13)
Browse files Browse the repository at this point in the history
Test using miniredis, a pure Go Redis server for unit tests.
  • Loading branch information
sudo-suhas authored Mar 5, 2021
1 parent 99f237a commit 603c290
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 66 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: build

on:
push:
tags: [v*]
branches: [master]
pull_request:

jobs:
# See https://github.com/mvdan/github-actions-golang
test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.15.x, 1.16.x]
steps:
- name: Install Go@v${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
# See https://github.com/actions/cache/blob/master/examples.md#go---modules
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: go test ./...

test-webui:
runs-on: ubuntu-latest
defaults:
run:
working-directory: webui/internal/assets
# See https://docs.github.com/en/actions/guides/building-and-testing-nodejs
steps:
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Checkout code
uses: actions/checkout@v2
# See https://github.com/actions/cache/blob/master/examples.md#node---yarn
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Test
run: yarn test
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# gocraft/work [![GoDoc](https://godoc.org/github.com/gocraft/work?status.png)](https://godoc.org/github.com/gocraft/work)
# gocraft/work [![PkgGoDev][pkg-go-dev-xgo-badge]][pkg-go-dev-xgo] [![build][github-workflow-badge]][github-workflow]

gocraft/work lets you enqueue and processes background jobs in Go. Jobs are durable and backed by Redis. Very similar to Sidekiq for Go.

Expand Down Expand Up @@ -375,3 +375,8 @@ These packages were developed by the [engineering team](https://eng.uservoice.co
* Jonathan Novak -- [https://github.com/cypriss](https://github.com/cypriss)
* Tai-Lin Chu -- [https://github.com/taylorchu](https://github.com/taylorchu)
* Sponsored by [UserVoice](https://eng.uservoice.com)

[pkg-go-dev-xgo-badge]: https://pkg.go.dev/badge/github.com/gojek/work
[pkg-go-dev-xgo]: https://pkg.go.dev/mod/github.com/gojek/work?tab=packages
[github-workflow-badge]: https://github.com/gojek/work/workflows/build/badge.svg
[github-workflow]: https://github.com/gojek/work/actions?query=workflow%3Abuild
30 changes: 15 additions & 15 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type TestContext struct{}

func TestClientWorkerPoolHeartbeats(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -64,7 +64,7 @@ func TestClientWorkerPoolHeartbeats(t *testing.T) {
}

func TestClientWorkerObservations(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -133,7 +133,7 @@ func TestClientWorkerObservations(t *testing.T) {
}

func TestClientQueues(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -184,7 +184,7 @@ func TestClientQueues(t *testing.T) {
}

func TestClientScheduledJobs(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -232,7 +232,7 @@ func TestClientScheduledJobs(t *testing.T) {
}

func TestClientRetryJobs(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -271,7 +271,7 @@ func TestClientRetryJobs(t *testing.T) {
}

func TestClientDeadJobs(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -326,7 +326,7 @@ func TestClientDeadJobs(t *testing.T) {
}

func TestClientDeleteDeadJob(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -355,7 +355,7 @@ func TestClientDeleteDeadJob(t *testing.T) {
}

func TestClientRetryDeadJob(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -411,7 +411,7 @@ func TestClientRetryDeadJob(t *testing.T) {
}

func TestClientRetryDeadJobWithArgs(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -455,7 +455,7 @@ func TestClientRetryDeadJobWithArgs(t *testing.T) {
}

func TestClientDeleteAllDeadJobs(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand All @@ -481,7 +481,7 @@ func TestClientDeleteAllDeadJobs(t *testing.T) {
}

func TestClientRetryAllDeadJobs(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -539,7 +539,7 @@ func TestClientRetryAllDeadJobs(t *testing.T) {
}

func TestClientRetryAllDeadJobsBig(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -608,7 +608,7 @@ func TestClientRetryAllDeadJobsBig(t *testing.T) {
}

func TestClientDeleteScheduledJob(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand All @@ -629,7 +629,7 @@ func TestClientDeleteScheduledJob(t *testing.T) {
}

func TestClientDeleteScheduledUniqueJob(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand All @@ -650,7 +650,7 @@ func TestClientDeleteScheduledUniqueJob(t *testing.T) {
}

func TestClientDeleteRetryJob(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "testwork"
cleanKeyspace(ns, pool)

Expand Down
18 changes: 13 additions & 5 deletions dead_pool_reaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestDeadPoolReaper(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -47,6 +47,10 @@ func TestDeadPoolReaper(t *testing.T) {
err = conn.Flush()
assert.NoError(t, err)

// Without this, the assertion for deadPools fails on GitHub CI. Could have
// something to do with in-memory redis instance.
time.Sleep(10*time.Millisecond)

// Test getting dead pool
reaper := newDeadPoolReaper(ns, pool, []string{})
deadPools, err := reaper.findDeadPools()
Expand Down Expand Up @@ -92,7 +96,7 @@ func TestDeadPoolReaper(t *testing.T) {
}

func TestDeadPoolReaperNoHeartbeat(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"

conn := pool.Get()
Expand Down Expand Up @@ -179,7 +183,7 @@ func TestDeadPoolReaperNoHeartbeat(t *testing.T) {
}

func TestDeadPoolReaperNoJobTypes(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)

Expand Down Expand Up @@ -209,6 +213,10 @@ func TestDeadPoolReaperNoJobTypes(t *testing.T) {
err = conn.Flush()
assert.NoError(t, err)

// Without this, the assertion for deadPools fails on GitHub CI. Could have
// something to do with in-memory redis instance.
time.Sleep(10*time.Millisecond)

// Test getting dead pool
reaper := newDeadPoolReaper(ns, pool, []string{})
deadPools, err := reaper.findDeadPools()
Expand Down Expand Up @@ -255,7 +263,7 @@ func TestDeadPoolReaperNoJobTypes(t *testing.T) {
}

func TestDeadPoolReaperWithWorkerPools(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
job1 := "job1"
stalePoolID := "aaa"
Expand Down Expand Up @@ -295,7 +303,7 @@ func TestDeadPoolReaperWithWorkerPools(t *testing.T) {
}

func TestDeadPoolReaperCleanStaleLocks(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)

Expand Down
12 changes: 6 additions & 6 deletions enqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestEnqueue(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestEnqueue(t *testing.T) {
}

func TestEnqueueIn(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestEnqueueIn(t *testing.T) {
}

func TestEnqueueUnique(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestEnqueueUnique(t *testing.T) {
}

func TestEnqueueUniqueIn(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestEnqueueUniqueByKey(t *testing.T) {
var arg3 string
var arg4 string

pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestEnqueueUniqueByKey(t *testing.T) {
}

func EnqueueUniqueInByKey(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"
cleanKeyspace(ns, pool)
enqueuer := NewEnqueuer(ns, pool)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.14

require (
github.com/albrow/jobs v0.4.2
github.com/alicebob/miniredis/v2 v2.14.3 // indirect
github.com/benmanns/goworker v0.1.3
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
github.com/albrow/jobs v0.4.2 h1:AhhNNgtnOz3h+Grt6uuRJP+uj/AVq+ZhIBY8Mzkf4TM=
github.com/albrow/jobs v0.4.2/go.mod h1:e4sWh7D1DxPbpxrzJhNo/cMARAljpTYF/osgh2j3+r8=
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk=
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/miniredis/v2 v2.14.3 h1:QWoo2wchYmLgOB6ctlTt2dewQ1Vu6phl+iQbwT8SYGo=
github.com/alicebob/miniredis/v2 v2.14.3/go.mod h1:gquAfGbzn92jvtrSC69+6zZnwSODVXVpYDRaGhWaL6I=
github.com/benmanns/goworker v0.1.3 h1:ekwn7WiKsn8oUOKfbHDqsA6g5bXz/uEZ9AdnKgtAECY=
github.com/benmanns/goworker v0.1.3/go.mod h1:Gj3m7lTyCswE3+Kta7c79CMOmm5rHJmj2qh/GAmojJ4=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
Expand All @@ -8,6 +12,9 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4Yn
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/braintree/manners v0.0.0-20160418043613-82a8879fc5fd h1:ePesaBzdTmoMQjwqRCLP2jY+jjWMBpwws/LEQdt1fMM=
github.com/braintree/manners v0.0.0-20160418043613-82a8879fc5fd/go.mod h1:TNehV1AhBwtT7Bd+rh8G6MoGDbBLNs/sKdk3nvr4Yzg=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 h1:kHaBemcxl8o/pQ5VM1c8PVE1PubbNx3mjUr09OqWGCs=
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575/go.mod h1:9d6lWj8KzO/fd/NrVaLscBKmPigpZpn5YawRPw+e3Yo=
github.com/customerio/gospec v0.0.0-20130710230057-a5cc0e48aa39 h1:O0YTztXI3XeJXlFhSo4wNb0VBVqSgT+hi/CjNWKvMnY=
Expand Down Expand Up @@ -46,9 +53,12 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/youtube/vitess v2.1.1+incompatible h1:SE+P7DNX/jw5RHFs5CHRhZQjq402EJFCD33JhzQMdDw=
github.com/youtube/vitess v2.1.1+incompatible/go.mod h1:hpMim5/30F1r+0P8GGtB29d0gWHr0IZ5unS+CG0zMx8=
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5ukMK0AMWEhFaL/lrEOaephfuoiARg=
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 h1:Jcxah/M+oLZ/R4/z5RzfPzGbPXnVDPkEDtf2JnuxN+U=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
2 changes: 1 addition & 1 deletion heartbeater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestHeartbeater(t *testing.T) {
pool := newTestPool(":6379")
pool := newTestPool(t)
ns := "work"

tMock := int64(1425263409)
Expand Down
Loading

0 comments on commit 603c290

Please sign in to comment.