Skip to content

Commit

Permalink
allow parallel tests by default but run them sequentially in the CI p…
Browse files Browse the repository at this point in the history
…ipeline
  • Loading branch information
jxsl13 committed Mar 15, 2024
1 parent f5cfb80 commit 626c0cd
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
run: docker-compose up -d

- name: Code Coverage
run: go test -timeout 900s -race -count=1 -covermode=atomic -coverprofile=coverage.txt ./...
run: go test -timeout 900s -race -count=1 -parallel 1 -covermode=atomic -coverprofile=coverage.txt ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ coverage.txt
DEBUG.md
debug.md
__debug_bin*
*.log
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ down:
docker-compose down

test:
go test -timeout 300s -v -race -count=1 ./...
go test -timeout 600ss -v -race -count=1 ./... > parallel.test.log

test-sequentially:
go test -timeout 900s -v -race -parallel 1 -count=1 ./... > sequential.test.log

count-tests:
grep -REn 'func Test.+\(.+testing\.T.*\)' . | wc -l
Expand All @@ -18,5 +21,5 @@ count-disconnect-tests:


pool.TestBatchSubscriberMaxBytes:
go test -timeout 0m30s github.com/jxsl13/amqpx/pool -run ^TestBatchSubscriberMaxBytes$ -v -count=1 -race 2>&1 > test.log
go test -timeout 0m30s github.com/jxsl13/amqpx/pool -run ^TestBatchSubscriberMaxBytes$ -v -count=1 -race 2>&1 > debug.test.log
cat test.log | grep 'INFO: session' | sort | uniq -c
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ A `Subscriber` must be `Start()`ed in order for it to create consumer goroutines

## Development

Tests can all be run in parallel but the parallel testing is disabled for now because of the GitHub runners starting to behave weirdly when under such a load.
That is why those tests were disabled for the CI pipeline.

Test flags you might want to add:
```shell
go test -v -race -count=1 ./...
Expand Down
28 changes: 14 additions & 14 deletions amqpx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
}

func TestExchangeDeclarePassive(t *testing.T) {

t.Parallel()
var (
amqp = amqpx.New()
ctx = context.TODO()
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestExchangeDeclarePassive(t *testing.T) {
}

func TestQueueDeclarePassive(t *testing.T) {

t.Parallel()
var (
amqp = amqpx.New()
ctx = context.TODO()
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestQueueDeclarePassive(t *testing.T) {
}

func TestAMQPXPub(t *testing.T) {

t.Parallel()
var (
amqp = amqpx.New()
ctx = context.TODO()
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestAMQPXPub(t *testing.T) {
}

func TestAMQPXSubAndPub(t *testing.T) {

t.Parallel()
var (
amqp = amqpx.New()
log = logging.NewTestLogger(t)
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestAMQPXSubAndPub(t *testing.T) {
}

func TestAMQPXSubAndPubMulti(t *testing.T) {

t.Parallel()
var (
amqp = amqpx.New()
log = logging.NewTestLogger(t)
Expand Down Expand Up @@ -319,7 +319,7 @@ func TestAMQPXSubAndPubMulti(t *testing.T) {
}

func TestAMQPXSubHandler(t *testing.T) {

t.Parallel()
var (
amqp = amqpx.New()
log = logging.NewTestLogger(t)
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestAMQPXSubHandler(t *testing.T) {
}

func TestCreateDeleteTopology(t *testing.T) {

t.Parallel()
var (
amqp = amqpx.New()
log = logging.NewTestLogger(t)
Expand Down Expand Up @@ -414,7 +414,7 @@ func TestCreateDeleteTopology(t *testing.T) {
}

func TestPauseResumeHandlerNoProcessing(t *testing.T) {

t.Parallel()
var (
amqp = amqpx.New()
log = logging.NewTestLogger(t)
Expand Down Expand Up @@ -484,7 +484,7 @@ func TestPauseResumeHandlerNoProcessing(t *testing.T) {
}

func TestHandlerPauseAndResume(t *testing.T) {

t.Parallel()
var wg sync.WaitGroup
defer wg.Wait()

Expand Down Expand Up @@ -647,7 +647,7 @@ func testHandlerPauseAndResume(t *testing.T, i int) {
}

func TestBatchHandlerPauseAndResume(t *testing.T) {

t.Parallel()
var wg sync.WaitGroup
defer wg.Wait()
for i := 0; i < 10; i++ {
Expand Down Expand Up @@ -808,7 +808,7 @@ func testBatchHandlerPauseAndResume(t *testing.T, i int) {
}

func TestQueueDeletedConsumerReconnect(t *testing.T) {

t.Parallel()
var (
err error
amqp = amqpx.New()
Expand Down Expand Up @@ -882,7 +882,7 @@ func TestQueueDeletedConsumerReconnect(t *testing.T) {
}

func TestQueueDeletedBatchConsumerReconnect(t *testing.T) {

t.Parallel()
var (
err error
amqp = amqpx.New()
Expand Down Expand Up @@ -977,7 +977,7 @@ type handlerStats interface {
}

func TestHandlerReset(t *testing.T) {

t.Parallel()
for i := 0; i < 5; i++ {
testHandlerReset(t, i)
}
Expand Down Expand Up @@ -1073,7 +1073,7 @@ func testHandlerReset(t *testing.T, i int) {
}

func TestBatchHandlerReset(t *testing.T) {

t.Parallel()
for i := 0; i < 5; i++ {
testBatchHandlerReset(t, i)
}
Expand Down
8 changes: 6 additions & 2 deletions internal/testutils/connect_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
]
*/
func TestGenerateProxyConfig(_ *testing.T) {
func TestGenerateProxyConfig(t *testing.T) {
t.Parallel()

list := []struct {
Name string `json:"name"`
Listen string `json:"listen"`
Expand Down Expand Up @@ -47,7 +49,9 @@ func TestGenerateProxyConfig(_ *testing.T) {
fmt.Println(string(data))
}

func TestGenerateDockerPortForwards(_ *testing.T) {
func TestGenerateDockerPortForwards(t *testing.T) {
t.Parallel()

nextConnectURL := NewConnectURLGenerator(ExcludedPorts...)

str := ""
Expand Down
4 changes: 2 additions & 2 deletions pool/connection_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestNewSingleConnectionPool(t *testing.T) {
t.Parallel() // can be run in parallel because the connection to the rabbitmq is never broken
t.Parallel()

poolName := testutils.FuncName()
ctx := context.TODO()
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestNewSingleConnectionPool(t *testing.T) {
}

func TestNewConnectionPool(t *testing.T) {
t.Parallel() // can be run in parallel because the connection to the rabbitmq is never broken
t.Parallel()

poolName := testutils.FuncName()

Expand Down
5 changes: 3 additions & 2 deletions pool/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestNewSingleConnection(t *testing.T) {

t.Parallel()
var (
ctx = context.TODO()
nextName = testutils.ConnectionNameGenerator()
Expand All @@ -36,7 +36,7 @@ func TestNewSingleConnection(t *testing.T) {
}

func TestManyNewConnection(t *testing.T) {

t.Parallel()
var (
ctx = context.TODO()
wg sync.WaitGroup
Expand Down Expand Up @@ -73,6 +73,7 @@ func TestManyNewConnection(t *testing.T) {
}

func TestNewSingleConnectionWithDisconnect(t *testing.T) {
t.Parallel()
var (
ctx = context.TODO()
proxyName, connectURL, _ = testutils.NextConnectURL()
Expand Down
2 changes: 1 addition & 1 deletion pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestMain(m *testing.M) {
}

func TestNewPool(t *testing.T) {

t.Parallel()
var (
ctx = context.TODO()
poolName = testutils.FuncName()
Expand Down
4 changes: 2 additions & 2 deletions pool/session_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestSingleSessionPool(t *testing.T) {

t.Parallel()
var (
poolName = testutils.FuncName()
ctx = context.TODO()
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestSingleSessionPool(t *testing.T) {
}

func TestNewSessionPool(t *testing.T) {

t.Parallel()
var (
poolName = testutils.FuncName()
ctx = context.TODO()
Expand Down
Loading

0 comments on commit 626c0cd

Please sign in to comment.