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
6 changes: 6 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v7

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
check-latest: true

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
Expand Down
42 changes: 33 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
GOTOOLCHAIN: local

jobs:
lint:
runs-on: ubuntu-latest
Expand All @@ -33,14 +36,15 @@ jobs:
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.7
version: v2.14.0
args: --verbose

test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
go: [1.25, 1.26]
go: ["1.26", "1.27"]
include:
- os: ubuntu-latest
go-build: ~/.cache/go-build
Expand All @@ -50,24 +54,25 @@ jobs:
GO111MODULE: on
GOPROXY: https://proxy.golang.org
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v7
with:
go-version: ${{ matrix.go }}

- name: Checkout Code
uses: actions/checkout@v7
with:
ref: ${{ github.ref }}

- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v7
with:
go-version: ${{ matrix.go }}
check-latest: true

- uses: actions/cache@v6
with:
path: |
${{ matrix.go-build }}
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
${{ runner.os }}-go-${{ matrix.go }}-
- name: Run Tests
run: |
go test -race -v -covermode=atomic -coverprofile=coverage.out
Expand All @@ -76,7 +81,26 @@ jobs:
run: |
go test -v -run=^$ -count 5 -benchmem -bench . ./...

- name: Build example modules
run: |
find _example -name go.mod -print0 | while IFS= read -r -d '' mod; do
(cd "$(dirname "$mod")" && go build -mod=readonly ./...)
done

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v7
with:
flags: ${{ matrix.os }},go-${{ matrix.go }}

vulnerability-scanning:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: 'fs'
ignore-unfixed: true
format: 'table'
exit-code: '1'
severity: 'CRITICAL,HIGH,MEDIUM'
3 changes: 2 additions & 1 deletion .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: "^1"
go-version-file: go.mod
check-latest: true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v7
with:
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version: 2

builds:
- # If true, skip the build.
# Useful for library projects.
Expand Down
2 changes: 1 addition & 1 deletion _example/example01/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module example

go 1.25.0
go 1.26.8

require (
github.com/golang-queue/contrib v1.1.0
Expand Down
2 changes: 1 addition & 1 deletion _example/example02/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module example

go 1.25.0
go 1.26.8

require (
github.com/golang-queue/contrib v1.1.0
Expand Down
2 changes: 1 addition & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func BenchmarkQueue(b *testing.B) {
b.ResetTimer()

m := job.NewMessage(&mockMessage{
message: "foo",
message: testMessageFoo,
})

for n := 0; n < b.N; n++ {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/golang-queue/queue

go 1.25
go 1.26.8

require (
github.com/appleboy/com v1.2.0
Expand Down
21 changes: 13 additions & 8 deletions ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"go.uber.org/mock/gomock"
)

const (
testMessageFoo = "foo"
testMessageTest = "test"
)

func TestMaxCapacity(t *testing.T) {
w := NewRing(WithQueueSize(2))

Expand All @@ -30,7 +35,7 @@ func TestMaxCapacity(t *testing.T) {

func TestCustomFuncAndWait(t *testing.T) {
m := mockMessage{
message: "foo",
message: testMessageFoo,
}
w := NewRing(
WithFn(func(ctx context.Context, m core.TaskMessage) error {
Expand Down Expand Up @@ -59,7 +64,7 @@ func TestCustomFuncAndWait(t *testing.T) {

func TestEnqueueJobAfterShutdown(t *testing.T) {
m := mockMessage{
message: "foo",
message: testMessageFoo,
}
w := NewRing()
q, err := NewQueue(
Expand All @@ -79,7 +84,7 @@ func TestEnqueueJobAfterShutdown(t *testing.T) {

func TestJobReachTimeout(t *testing.T) {
m := mockMessage{
message: "foo",
message: testMessageFoo,
}
w := NewRing(
WithFn(func(ctx context.Context, m core.TaskMessage) error {
Expand Down Expand Up @@ -112,7 +117,7 @@ func TestJobReachTimeout(t *testing.T) {

func TestCancelJobAfterShutdown(t *testing.T) {
m := mockMessage{
message: "foo",
message: testMessageFoo,
}
w := NewRing(
WithLogger(NewEmptyLogger()),
Expand Down Expand Up @@ -189,7 +194,7 @@ func TestGoroutineLeak(t *testing.T) {

func TestGoroutinePanic(t *testing.T) {
m := mockMessage{
message: "foo",
message: testMessageFoo,
}
w := NewRing(
WithFn(func(ctx context.Context, m core.TaskMessage) error {
Expand Down Expand Up @@ -512,7 +517,7 @@ func TestErrNoTaskInQueue(t *testing.T) {
func BenchmarkRingQueue(b *testing.B) {
b.Run("queue and request operations", func(b *testing.B) {
w := NewRing(WithQueueSize(1000))
m := mockMessage{message: "test"}
m := mockMessage{message: testMessageTest}

b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
Expand All @@ -525,7 +530,7 @@ func BenchmarkRingQueue(b *testing.B) {

b.Run("concurrent queue operations", func(b *testing.B) {
w := NewRing(WithQueueSize(1000))
m := mockMessage{message: "test"}
m := mockMessage{message: testMessageTest}

b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
Expand All @@ -537,7 +542,7 @@ func BenchmarkRingQueue(b *testing.B) {

b.Run("resize operations", func(b *testing.B) {
w := NewRing()
m := mockMessage{message: "test"}
m := mockMessage{message: testMessageTest}

b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand Down
Loading