Procházet zdrojové kódy

Fix leveldb test race (#10054)

Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
tags/v1.10.5
Lunny Xiao před 4 roky
rodič
revize
eac5142ac7
Žádný účet není propojen s e-mailovou adresou tvůrce revize
1 změnil soubory, kde provedl 18 přidání a 0 odebrání
  1. 18
    0
      modules/queue/queue_disk_test.go

+ 18
- 0
modules/queue/queue_disk_test.go Zobrazit soubor

@@ -8,6 +8,7 @@ import (
"context"
"io/ioutil"
"os"
"sync"
"testing"
"time"

@@ -24,6 +25,7 @@ func TestLevelQueue(t *testing.T) {
}
}

var lock sync.Mutex
queueShutdown := []func(){}
queueTerminate := []func(){}

@@ -46,9 +48,13 @@ func TestLevelQueue(t *testing.T) {
assert.NoError(t, err)

go queue.Run(func(_ context.Context, shutdown func()) {
lock.Lock()
queueShutdown = append(queueShutdown, shutdown)
lock.Unlock()
}, func(_ context.Context, terminate func()) {
lock.Lock()
queueTerminate = append(queueTerminate, terminate)
lock.Unlock()
})

test1 := testData{"A", 1}
@@ -72,9 +78,12 @@ func TestLevelQueue(t *testing.T) {
err = queue.Push(test1)
assert.Error(t, err)

lock.Lock()
for _, callback := range queueShutdown {
callback()
}
lock.Unlock()

time.Sleep(200 * time.Millisecond)
err = queue.Push(&test1)
assert.NoError(t, err)
@@ -85,9 +94,11 @@ func TestLevelQueue(t *testing.T) {
assert.Fail(t, "Handler processing should have stopped")
default:
}
lock.Lock()
for _, callback := range queueTerminate {
callback()
}
lock.Unlock()

// Reopen queue
queue, err = NewWrappedQueue(handle,
@@ -109,9 +120,13 @@ func TestLevelQueue(t *testing.T) {
assert.NoError(t, err)

go queue.Run(func(_ context.Context, shutdown func()) {
lock.Lock()
queueShutdown = append(queueShutdown, shutdown)
lock.Unlock()
}, func(_ context.Context, terminate func()) {
lock.Lock()
queueTerminate = append(queueTerminate, terminate)
lock.Unlock()
})

result3 := <-handleChan
@@ -121,10 +136,13 @@ func TestLevelQueue(t *testing.T) {
result4 := <-handleChan
assert.Equal(t, test2.TestString, result4.TestString)
assert.Equal(t, test2.TestInt, result4.TestInt)

lock.Lock()
for _, callback := range queueShutdown {
callback()
}
for _, callback := range queueTerminate {
callback()
}
lock.Unlock()
}

Načítá se…
Zrušit
Uložit