Skip to content
Snippets Groups Projects
Commit 4ddb8455 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

mitigated data race

parent 7a7f7ab5
No related branches found
No related tags found
2 merge requests!120Resolve "Code Quality",!90Develop
Pipeline #67286 failed
...@@ -8,6 +8,8 @@ variables: ...@@ -8,6 +8,8 @@ variables:
DOCKER_IMAGE_SHA: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA DOCKER_IMAGE_SHA: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
build:docker: build:docker:
tags:
- dind
stage: build stage: build
rules: rules:
- if: $CI_COMMIT_BRANCH == "develop" - if: $CI_COMMIT_BRANCH == "develop"
......
...@@ -3,8 +3,8 @@ package nucleus ...@@ -3,8 +3,8 @@ package nucleus
import ( import (
"context" "context"
"net/http" "net/http"
"reflect"
"testing" "testing"
"time"
) )
func TestRun(t *testing.T) { func TestRun(t *testing.T) {
...@@ -20,33 +20,38 @@ func TestRun(t *testing.T) { ...@@ -20,33 +20,38 @@ func TestRun(t *testing.T) {
{ {
name: "liveliness indicator", name: "liveliness indicator",
args: args{request: apiEndpoint + "/livez"}, args: args{request: apiEndpoint + "/livez"},
want: &http.Response{StatusCode: http.StatusOK}, want: http.StatusOK,
wantErr: false, wantErr: false,
}, },
{ {
name: "readyness indicator", name: "readyness indicator",
args: args{request: apiEndpoint + "/readyz"}, args: args{request: apiEndpoint + "/readyz"},
want: &http.Response{StatusCode: http.StatusOK}, want: http.StatusOK,
wantErr: false, wantErr: false,
}, },
{ {
name: "init", name: "init",
args: args{request: apiEndpoint + "/api?q=init"}, args: args{request: apiEndpoint + "/api?q=init"},
want: &http.Response{StatusCode: http.StatusOK}, want: http.StatusOK,
wantErr: false, wantErr: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
ctx, cancel := context.WithCancel(context.Background())
go func() {
if err := Run(ctx); (err != nil) != tt.wantErr {
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
}
}()
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) got, err := http.Get(tt.args.request)
go func() { if err != nil {
if err := Run(ctx); (err != nil) != tt.wantErr { t.Error(err)
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr) }
} if !reflect.DeepEqual(got.StatusCode, tt.want) {
}() t.Errorf("Run() got: %v, want %v", got.StatusCode, tt.want)
time.Sleep(time.Second) }
cancel()
time.Sleep(time.Second)
}) })
cancel()
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment