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:
DOCKER_IMAGE_SHA: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
build:docker:
tags:
- dind
stage: build
rules:
- if: $CI_COMMIT_BRANCH == "develop"
......
......@@ -3,8 +3,8 @@ package nucleus
import (
"context"
"net/http"
"reflect"
"testing"
"time"
)
func TestRun(t *testing.T) {
......@@ -20,33 +20,38 @@ func TestRun(t *testing.T) {
{
name: "liveliness indicator",
args: args{request: apiEndpoint + "/livez"},
want: &http.Response{StatusCode: http.StatusOK},
want: http.StatusOK,
wantErr: false,
},
{
name: "readyness indicator",
args: args{request: apiEndpoint + "/readyz"},
want: &http.Response{StatusCode: http.StatusOK},
want: http.StatusOK,
wantErr: false,
},
{
name: "init",
args: args{request: apiEndpoint + "/api?q=init"},
want: &http.Response{StatusCode: http.StatusOK},
want: http.StatusOK,
wantErr: false,
},
}
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) {
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)
}
}()
time.Sleep(time.Second)
cancel()
time.Sleep(time.Second)
got, err := http.Get(tt.args.request)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(got.StatusCode, tt.want) {
t.Errorf("Run() got: %v, want %v", got.StatusCode, tt.want)
}
})
cancel()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment