silenced race detector errors per #7484
This commit is contained in:
@@ -3,6 +3,7 @@ package cron
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"slices"
|
"slices"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -253,6 +254,8 @@ func TestCronJobs(t *testing.T) {
|
|||||||
func TestCronStartStop(t *testing.T) {
|
func TestCronStartStop(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
var mu sync.Mutex
|
||||||
|
|
||||||
test1 := 0
|
test1 := 0
|
||||||
test2 := 0
|
test2 := 0
|
||||||
|
|
||||||
@@ -261,15 +264,17 @@ func TestCronStartStop(t *testing.T) {
|
|||||||
c.SetInterval(250 * time.Millisecond)
|
c.SetInterval(250 * time.Millisecond)
|
||||||
|
|
||||||
c.Add("test1", "* * * * *", func() {
|
c.Add("test1", "* * * * *", func() {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
test1++
|
test1++
|
||||||
})
|
})
|
||||||
|
|
||||||
c.Add("test2", "* * * * *", func() {
|
c.Add("test2", "* * * * *", func() {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
test2++
|
test2++
|
||||||
})
|
})
|
||||||
|
|
||||||
expectedCalls := 2
|
|
||||||
|
|
||||||
// call twice Start to check if the previous ticker will be reseted
|
// call twice Start to check if the previous ticker will be reseted
|
||||||
c.Start()
|
c.Start()
|
||||||
c.Start()
|
c.Start()
|
||||||
@@ -280,12 +285,16 @@ func TestCronStartStop(t *testing.T) {
|
|||||||
c.Stop()
|
c.Stop()
|
||||||
c.Stop()
|
c.Stop()
|
||||||
|
|
||||||
|
expectedCalls := 2
|
||||||
|
|
||||||
|
mu.Lock()
|
||||||
if test1 != expectedCalls {
|
if test1 != expectedCalls {
|
||||||
t.Fatalf("Expected %d test1, got %d", expectedCalls, test1)
|
t.Fatalf("Expected %d test1, got %d", expectedCalls, test1)
|
||||||
}
|
}
|
||||||
if test2 != expectedCalls {
|
if test2 != expectedCalls {
|
||||||
t.Fatalf("Expected %d test2, got %d", expectedCalls, test2)
|
t.Fatalf("Expected %d test2, got %d", expectedCalls, test2)
|
||||||
}
|
}
|
||||||
|
mu.Unlock()
|
||||||
|
|
||||||
// resume for 1 seconds
|
// resume for 1 seconds
|
||||||
c.Start()
|
c.Start()
|
||||||
@@ -296,10 +305,12 @@ func TestCronStartStop(t *testing.T) {
|
|||||||
|
|
||||||
expectedCalls += 4
|
expectedCalls += 4
|
||||||
|
|
||||||
|
mu.Lock()
|
||||||
if test1 != expectedCalls {
|
if test1 != expectedCalls {
|
||||||
t.Fatalf("Expected %d test1, got %d", expectedCalls, test1)
|
t.Fatalf("Expected %d test1, got %d", expectedCalls, test1)
|
||||||
}
|
}
|
||||||
if test2 != expectedCalls {
|
if test2 != expectedCalls {
|
||||||
t.Fatalf("Expected %d test2, got %d", expectedCalls, test2)
|
t.Fatalf("Expected %d test2, got %d", expectedCalls, test2)
|
||||||
}
|
}
|
||||||
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -741,6 +742,7 @@ type testTableStruct struct {
|
|||||||
|
|
||||||
type testDB struct {
|
type testDB struct {
|
||||||
*dbx.DB
|
*dbx.DB
|
||||||
|
mu sync.Mutex
|
||||||
CalledQueries []string
|
CalledQueries []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,6 +767,8 @@ func createTestDB() (*testDB, error) {
|
|||||||
db.Insert("test", dbx.Params{"id": 1, "test1": 1, "test2": "test2.1"}).Execute()
|
db.Insert("test", dbx.Params{"id": 1, "test1": 1, "test2": "test2.1"}).Execute()
|
||||||
db.Insert("test", dbx.Params{"id": 2, "test1": 2, "test2": "test2.2"}).Execute()
|
db.Insert("test", dbx.Params{"id": 2, "test1": 2, "test2": "test2.2"}).Execute()
|
||||||
db.QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {
|
db.QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {
|
||||||
|
db.mu.Lock()
|
||||||
|
defer db.mu.Unlock()
|
||||||
db.CalledQueries = append(db.CalledQueries, sql)
|
db.CalledQueries = append(db.CalledQueries, sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package subscriptions_test
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -208,12 +209,16 @@ func TestDiscard(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSend(t *testing.T) {
|
func TestSend(t *testing.T) {
|
||||||
|
var mu sync.Mutex
|
||||||
|
|
||||||
c := subscriptions.NewDefaultClient()
|
c := subscriptions.NewDefaultClient()
|
||||||
|
|
||||||
received := []string{}
|
received := []string{}
|
||||||
go func() {
|
go func() {
|
||||||
for m := range c.Channel() {
|
for m := range c.Channel() {
|
||||||
|
mu.Lock()
|
||||||
received = append(received, m.Name)
|
received = append(received, m.Name)
|
||||||
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -226,6 +231,8 @@ func TestSend(t *testing.T) {
|
|||||||
|
|
||||||
expected := []string{"m1", "m2"}
|
expected := []string{"m1", "m2"}
|
||||||
|
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
if len(received) != len(expected) {
|
if len(received) != len(expected) {
|
||||||
t.Fatalf("Expected %d messages, got %d", len(expected), len(received))
|
t.Fatalf("Expected %d messages, got %d", len(expected), len(received))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user