mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-05-18 22:00:21 -04:00
silenced race detector errors per #7484
This commit is contained in:
@@ -3,6 +3,7 @@ package cron
|
||||
import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -253,6 +254,8 @@ func TestCronJobs(t *testing.T) {
|
||||
func TestCronStartStop(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var mu sync.Mutex
|
||||
|
||||
test1 := 0
|
||||
test2 := 0
|
||||
|
||||
@@ -261,15 +264,17 @@ func TestCronStartStop(t *testing.T) {
|
||||
c.SetInterval(250 * time.Millisecond)
|
||||
|
||||
c.Add("test1", "* * * * *", func() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
test1++
|
||||
})
|
||||
|
||||
c.Add("test2", "* * * * *", func() {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
test2++
|
||||
})
|
||||
|
||||
expectedCalls := 2
|
||||
|
||||
// call twice Start to check if the previous ticker will be reseted
|
||||
c.Start()
|
||||
c.Start()
|
||||
@@ -280,12 +285,16 @@ func TestCronStartStop(t *testing.T) {
|
||||
c.Stop()
|
||||
c.Stop()
|
||||
|
||||
expectedCalls := 2
|
||||
|
||||
mu.Lock()
|
||||
if test1 != expectedCalls {
|
||||
t.Fatalf("Expected %d test1, got %d", expectedCalls, test1)
|
||||
}
|
||||
if test2 != expectedCalls {
|
||||
t.Fatalf("Expected %d test2, got %d", expectedCalls, test2)
|
||||
}
|
||||
mu.Unlock()
|
||||
|
||||
// resume for 1 seconds
|
||||
c.Start()
|
||||
@@ -296,10 +305,12 @@ func TestCronStartStop(t *testing.T) {
|
||||
|
||||
expectedCalls += 4
|
||||
|
||||
mu.Lock()
|
||||
if test1 != expectedCalls {
|
||||
t.Fatalf("Expected %d test1, got %d", expectedCalls, test1)
|
||||
}
|
||||
if test2 != expectedCalls {
|
||||
t.Fatalf("Expected %d test2, got %d", expectedCalls, test2)
|
||||
}
|
||||
mu.Unlock()
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -741,6 +742,7 @@ type testTableStruct struct {
|
||||
|
||||
type testDB struct {
|
||||
*dbx.DB
|
||||
mu sync.Mutex
|
||||
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": 2, "test1": 2, "test2": "test2.2"}).Execute()
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package subscriptions_test
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -208,12 +209,16 @@ func TestDiscard(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSend(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
|
||||
c := subscriptions.NewDefaultClient()
|
||||
|
||||
received := []string{}
|
||||
go func() {
|
||||
for m := range c.Channel() {
|
||||
mu.Lock()
|
||||
received = append(received, m.Name)
|
||||
mu.Unlock()
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -226,6 +231,8 @@ func TestSend(t *testing.T) {
|
||||
|
||||
expected := []string{"m1", "m2"}
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(received) != len(expected) {
|
||||
t.Fatalf("Expected %d messages, got %d", len(expected), len(received))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user