Skip to content

Commit 33a428e

Browse files
authored
Merge pull request #395 from cschleiden/monoprocess-tests
Run in CI and fix monoprocess backend tests
2 parents 924d4df + cb663ab commit 33a428e

File tree

3 files changed

+115
-107
lines changed

3 files changed

+115
-107
lines changed

.github/workflows/go.yml

Lines changed: 103 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Build & Test
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88
workflow_dispatch:
99

1010
concurrency:
@@ -16,116 +16,122 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/checkout@v4
20-
21-
- name: Set up Go
22-
uses: actions/setup-go@v5
23-
with:
24-
go-version: 1.22
25-
check-latest: true
26-
cache: true
27-
28-
- name: Build
29-
run: go build -v ./...
30-
31-
- name: Tests
32-
run: |
33-
go install github.com/jstemmer/go-junit-report/v2@latest
34-
go test -short -timeout 120s -race -count 1 -v ./... 2>&1 | go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
35-
36-
37-
- name: Test Summary
38-
uses: test-summary/action@v2
39-
with:
40-
paths: |
41-
${{ github.workspace }}/report.xml
42-
if: always()
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: 1.22
25+
check-latest: true
26+
cache: true
27+
28+
- name: Build
29+
run: go build -v ./...
30+
31+
- name: Tests
32+
run: |
33+
go install github.com/jstemmer/go-junit-report/v2@latest
34+
go test -short -timeout 120s -race -count 1 -v ./... 2>&1 | go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
35+
36+
- name: Test Summary
37+
uses: test-summary/action@v2
38+
with:
39+
paths: |
40+
${{ github.workspace }}/report.xml
41+
if: always()
4342

4443
test_redis:
4544
runs-on: ubuntu-latest
4645
needs: build
4746

4847
steps:
49-
- uses: actions/checkout@v3
50-
51-
- name: Set up Go
52-
uses: actions/setup-go@v3
53-
with:
54-
go-version: 1.21
55-
check-latest: true
56-
cache: true
57-
58-
- name: Start Redis
59-
uses: shogo82148/actions-setup-redis@v1
60-
with:
61-
auto-start: true
62-
redis-port: 6379
63-
redis-version: '6.2'
64-
redis-conf: 'requirepass RedisPassw0rd'
65-
66-
- name: Tests
67-
run: |
68-
go install github.com/jstemmer/go-junit-report/v2@latest
69-
go test -timeout 120s -race -count 1 -v github.com/cschleiden/go-workflows/backend/redis 2>&1 | go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
70-
71-
- name: Test Summary
72-
uses: test-summary/action@v2
73-
with:
74-
paths: |
75-
${{ github.workspace }}/report.xml
76-
if: always()
48+
- uses: actions/checkout@v3
49+
50+
- name: Set up Go
51+
uses: actions/setup-go@v3
52+
with:
53+
go-version: 1.21
54+
check-latest: true
55+
cache: true
56+
57+
- name: Start Redis
58+
uses: shogo82148/actions-setup-redis@v1
59+
with:
60+
auto-start: true
61+
redis-port: 6379
62+
redis-version: "6.2"
63+
redis-conf: "requirepass RedisPassw0rd"
64+
65+
- name: Tests
66+
run: |
67+
go install github.com/jstemmer/go-junit-report/v2@latest
68+
go test -timeout 120s -race -count 1 -v github.com/cschleiden/go-workflows/backend/redis 2>&1 | go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
69+
70+
- name: Test Summary
71+
uses: test-summary/action@v2
72+
with:
73+
paths: |
74+
${{ github.workspace }}/report.xml
75+
if: always()
7776

7877
test_sqlite:
7978
runs-on: ubuntu-latest
8079
needs: build
8180

8281
steps:
83-
- uses: actions/checkout@v3
84-
85-
- name: Set up Go
86-
uses: actions/setup-go@v3
87-
with:
88-
go-version: 1.21
89-
check-latest: true
90-
cache: true
91-
92-
- name: Tests
93-
run: |
94-
go install github.com/jstemmer/go-junit-report/v2@latest
95-
go test -timeout 120s -race -count 1 -v github.com/cschleiden/go-workflows/backend/sqlite 2>&1 | go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
96-
97-
- name: Test Summary
98-
uses: test-summary/action@v2
99-
with:
100-
paths: |
101-
${{ github.workspace }}/report.xml
102-
if: always()
82+
- uses: actions/checkout@v3
83+
84+
- name: Set up Go
85+
uses: actions/setup-go@v3
86+
with:
87+
go-version: 1.21
88+
check-latest: true
89+
cache: true
90+
91+
- name: Install dependencies
92+
run: |
93+
go install github.com/jstemmer/go-junit-report/v2@latest
94+
95+
- name: Tests (sqlite)
96+
run: |
97+
go test -timeout 120s -race -count 1 -v github.com/cschleiden/go-workflows/backend/sqlite 2>&1 | go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
98+
99+
- name: Tests (monoprocess backend)
100+
run: |
101+
go test -timeout 120s -race -count 1 -v github.com/cschleiden/go-workflows/backend/monoprocess 2>&1 | go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
102+
103+
- name: Test Summary
104+
uses: test-summary/action@v2
105+
with:
106+
paths: |
107+
${{ github.workspace }}/report.xml
108+
if: always()
103109

104110
test_mysql:
105111
runs-on: ubuntu-latest
106112
needs: build
107113

108114
steps:
109-
- uses: actions/checkout@v3
110-
111-
- name: Set up Go
112-
uses: actions/setup-go@v3
113-
with:
114-
go-version: 1.21
115-
check-latest: true
116-
cache: true
117-
118-
- name: Start MySQL
119-
run: sudo /etc/init.d/mysql start
120-
121-
- name: Tests
122-
run: |
123-
go install github.com/jstemmer/go-junit-report/v2@latest
124-
go test -timeout 120s -race -count 1 -v github.com/cschleiden/go-workflows/backend/mysql 2>&1 | go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
125-
126-
- name: Test Summary
127-
uses: test-summary/action@v2
128-
with:
129-
paths: |
130-
${{ github.workspace }}/report.xml
131-
if: always()
115+
- uses: actions/checkout@v3
116+
117+
- name: Set up Go
118+
uses: actions/setup-go@v3
119+
with:
120+
go-version: 1.21
121+
check-latest: true
122+
cache: true
123+
124+
- name: Start MySQL
125+
run: sudo /etc/init.d/mysql start
126+
127+
- name: Tests
128+
run: |
129+
go install github.com/jstemmer/go-junit-report/v2@latest
130+
go test -timeout 120s -race -count 1 -v github.com/cschleiden/go-workflows/backend/mysql 2>&1 | go-junit-report -set-exit-code -iocopy -out "${{ github.workspace }}/report.xml"
131+
132+
- name: Test Summary
133+
uses: test-summary/action@v2
134+
with:
135+
paths: |
136+
${{ github.workspace }}/report.xml
137+
if: always()

backend/sqlite/sqlite.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ import (
3333
var migrationsFS embed.FS
3434

3535
func NewInMemoryBackend(opts ...option) *sqliteBackend {
36-
b := newSqliteBackend("file::memory:?mode=memory&cache=shared", opts...)
36+
// Use a unique named in-memory database
37+
dsn := fmt.Sprintf("file:%s?mode=memory&cache=shared", uuid.NewString())
38+
b := newSqliteBackend(dsn, opts...)
3739

3840
b.db.SetConnMaxIdleTime(0)
3941
b.db.SetMaxIdleConns(1)
4042

41-
// WORKAROUND: Keep a connection open at all times to prevent hte in-memory db from being dropped
43+
// WORKAROUND: Keep a connection open at all times to prevent the in-memory db from being dropped
4244
b.db.SetMaxOpenConns(2)
4345

4446
var err error

backend/test/backendtest.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ func BackendTest(t *testing.T, setup func(options ...backend.BackendOption) Test
170170
queues := []workflow.Queue{workflow.QueueDefault, core.QueueSystem}
171171
require.NoError(t, b.PrepareWorkflowQueues(ctx, queues))
172172

173-
task, err := b.GetWorkflowTask(ctx, queues)
174-
require.NoError(t, err)
173+
tctx, cancel := context.WithTimeout(ctx, time.Millisecond*100)
174+
task, err := b.GetWorkflowTask(tctx, queues)
175+
cancel()
176+
require.True(t, err == nil || errors.Is(err, context.DeadlineExceeded))
175177
require.Nil(t, task)
176178

177179
customQueues := []workflow.Queue{"customQueue"}
@@ -423,15 +425,13 @@ func BackendTest(t *testing.T, setup func(options ...backend.BackendOption) Test
423425

424426
require.NoError(t, b.PrepareActivityQueues(ctx, []workflow.Queue{workflow.QueueDefault, "custom"}))
425427

426-
task, err := b.GetActivityTask(ctx, []workflow.Queue{workflow.QueueDefault})
427-
require.NoError(t, err)
428+
tctx, cancel := context.WithTimeout(ctx, time.Millisecond*100)
429+
task, err := b.GetActivityTask(tctx, []workflow.Queue{workflow.QueueDefault})
430+
cancel()
431+
require.True(t, err == nil || errors.Is(err, context.DeadlineExceeded))
428432
require.NotNil(t, task)
429433
require.Equal(t, wfiDefault.InstanceID, task.WorkflowInstance.InstanceID)
430434

431-
task, err = b.GetActivityTask(ctx, []workflow.Queue{workflow.QueueDefault})
432-
require.NoError(t, err)
433-
require.Nil(t, task)
434-
435435
customQueue := workflow.Queue("custom")
436436
wfiCustom := runWorkflowWithActivity(t, ctx, b, core.QueueDefault, customQueue)
437437

0 commit comments

Comments
 (0)