Skip to content

Commit

Permalink
Merge pull request #30 from rafaeljesus/feature/improve-execution-of-…
Browse files Browse the repository at this point in the history
…integration-test

Improve make integration tests
  • Loading branch information
rafaeljesus authored May 1, 2018
2 parents 9007c9f + a75961e commit 15a5619
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all deps test
.PHONY: all deps test integration-test-ci

all: deps test
all: deps test integration-test

deps:
@go get -u github.com/golang/dep/cmd/dep
Expand All @@ -10,4 +10,11 @@ test:
@go test -v -race -cover

integration-test:
@docker-compose up -d
@sleep 3
AMQP_DSN="amqp://guest:guest@`docker-compose port rabbit 5672`/" \
go test -v -cover integration/rabbus_integration_test.go -bench .
@docker-compose down -v

integration-test-ci:
@go test -v -race -cover integration/rabbus_integration_test.go -bench .
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ machine:
environment:
IMPORT_PATH: "/home/ubuntu/.go_workspace/src/github.com/rafaeljesus"
APP_PATH: "$IMPORT_PATH/rabbus"
RABBUS_DSN: "amqp://localhost:5672"
AMQP_DSN: "amqp://localhost:5672"
services:
- rabbitmq-server

Expand All @@ -16,4 +16,4 @@ dependencies:

test:
override:
- cd "$APP_PATH" && make test && make integration-test
- cd "$APP_PATH" && make test && make integration-test-ci
13 changes: 4 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
version: '2'
version: '3'
services:
rabbitmq:
container_name: dev_rabbitmq
image: rabbitmq:3.5.6-management
hostname: rabbitmq
rabbit:
image: rabbitmq:3.6-management-alpine
ports:
- "5672:5672"
- "15672:15672"
volumes:
- ./data/rabbitmq:/var/lib/rabbitmq
- "5672"
22 changes: 17 additions & 5 deletions integration/rabbus_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rabbus

import (
"context"
"os"
"strconv"
"sync"
"testing"
Expand All @@ -11,14 +12,21 @@ import (
)

const (
RABBUS_DSN = "amqp://localhost:5672"
amqpDsnEnv = "AMQP_DSN"
)

var (
amqpDsn string
timeout = time.After(3 * time.Second)
)

func TestRabbus(t *testing.T) {
if os.Getenv(amqpDsnEnv) == "" {
t.SkipNow()
}

amqpDsn = os.Getenv(amqpDsnEnv)

t.Parallel()

tests := []struct {
Expand All @@ -39,13 +47,17 @@ func TestRabbus(t *testing.T) {
}

func BenchmarkRabbus(b *testing.B) {
if os.Getenv(amqpDsnEnv) == "" {
b.SkipNow()
}

tests := []struct {
scenario string
function func(*testing.B)
}{
{
scenario: "rabbus emit async benchmark",
function: benchmarkEmitAsync,
"rabbus emit async benchmark",
benchmarkEmitAsync,
},
}

Expand All @@ -58,7 +70,7 @@ func BenchmarkRabbus(b *testing.B) {

func testRabbusPublishSubscribe(t *testing.T) {
r, err := rabbus.New(
RABBUS_DSN,
amqpDsn,
rabbus.Durable(true),
rabbus.Attempts(5),
rabbus.BreakerTimeout(time.Second*2),
Expand Down Expand Up @@ -127,7 +139,7 @@ outer:

func benchmarkEmitAsync(b *testing.B) {
r, err := rabbus.New(
RABBUS_DSN,
amqpDsn,
rabbus.Attempts(1),
rabbus.BreakerTimeout(time.Second*2),
)
Expand Down

0 comments on commit 15a5619

Please sign in to comment.