fix: add mutex to fix race conditions for consumers

This commit is contained in:
2022-06-16 11:52:48 +02:00
parent 7db3319133
commit 1e4b943789
5 changed files with 23 additions and 29 deletions
+8 -11
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Unbound Software Development Svenska AB
// Copyright (c) 2022 Unbound Software Development Svenska AB
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
@@ -21,8 +21,10 @@ package apex
import (
"fmt"
"reflect"
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMock_Check(t *testing.T) {
@@ -48,23 +50,18 @@ func TestMock_Check(t *testing.T) {
name: "different",
fields: fields{Logged: []string{"same"}},
args: args{wantLogged: []string{"different"}},
want: []string{`Logger() got []string{
"same",
}, want []string{
"different",
}`},
want: []string{"\n\tError Trace:\tmocks.go:63\n\t \t\t\t\tmocks_test.go:63\n\tError: \tNot equal: \n\t \texpected: []string{\"different\"}\n\t \tactual : []string{\"same\"}\n\t \t\n\t \tDiff:\n\t \t--- Expected\n\t \t+++ Actual\n\t \t@@ -1,3 +1,3 @@\n\t \t ([]string) (len=1) {\n\t \t- (string) (len=9) \"different\"\n\t \t+ (string) (len=4) \"same\"\n\t \t }\n\tTest: \t\n"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &Mock{
Logged: tt.fields.Logged,
RWMutex: &sync.RWMutex{},
Logged: tt.fields.Logged,
}
temp := &MockT{}
m.Check(temp, tt.args.wantLogged)
if !reflect.DeepEqual(temp.errors, tt.want) {
t.Errorf("Check() got %+v, want %+v", temp.errors, tt.want)
}
assert.Equal(t, tt.want, temp.errors)
})
}
}