498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
60 lines
996 B
Go
60 lines
996 B
Go
package helper
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/cockroachdb/errors"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestScanner(t *testing.T) {
|
|
h := NewScannerHelper("test")
|
|
assert.NotNil(t, h.Context())
|
|
assert.Equal(t, h.Name(), "test")
|
|
assert.NotNil(t, h.Context())
|
|
|
|
select {
|
|
case <-h.Done():
|
|
t.Errorf("should not done")
|
|
return
|
|
case <-h.Context().Done():
|
|
t.Error("should not cancel")
|
|
return
|
|
default:
|
|
}
|
|
|
|
finishErr := errors.New("test")
|
|
|
|
ch := make(chan struct{})
|
|
go func() {
|
|
defer close(ch)
|
|
done := false
|
|
cancel := false
|
|
cancelCh := h.Context().Done()
|
|
doneCh := h.Done()
|
|
for i := 0; ; i += 1 {
|
|
select {
|
|
case <-doneCh:
|
|
done = true
|
|
doneCh = nil
|
|
case <-cancelCh:
|
|
cancel = true
|
|
cancelCh = nil
|
|
h.Finish(finishErr)
|
|
}
|
|
if cancel && done {
|
|
return
|
|
}
|
|
switch i {
|
|
case 0:
|
|
assert.True(t, cancel && !done)
|
|
case 1:
|
|
assert.True(t, cancel && done)
|
|
}
|
|
}
|
|
}()
|
|
h.Close()
|
|
assert.ErrorIs(t, h.Error(), finishErr)
|
|
<-ch
|
|
}
|