plugins: fix test data race.

This commit is contained in:
James Rasell 2021-06-15 09:31:08 +02:00
parent f919ddef55
commit 87413ff0cd
No known key found for this signature in database
GPG Key ID: AA7D460F5C8377AA
1 changed files with 7 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"sync"
"sync/atomic"
"testing"
"time"
@ -53,7 +54,9 @@ func TestBaseDriver_Fingerprint(t *testing.T) {
},
}
var complete bool
var complete atomic.Value
complete.Store(false)
impl := &MockDriver{
FingerprintF: func(ctx context.Context) (<-chan *drivers.Fingerprint, error) {
ch := make(chan *drivers.Fingerprint)
@ -62,7 +65,7 @@ func TestBaseDriver_Fingerprint(t *testing.T) {
ch <- fingerprints[0]
time.Sleep(500 * time.Millisecond)
ch <- fingerprints[1]
complete = true
complete.Store(true)
}()
return ch, nil
},
@ -91,10 +94,9 @@ func TestBaseDriver_Fingerprint(t *testing.T) {
require.Fail("did not receive fingerprint[1]")
}
}()
require.False(complete)
require.False(complete.Load().(bool))
wg.Wait()
require.True(complete)
require.True(complete.Load().(bool))
}
func TestBaseDriver_RecoverTask(t *testing.T) {