Improve protocol tests, close handling
This commit is contained in:
@@ -8,20 +8,21 @@ import (
|
||||
)
|
||||
|
||||
type TestModel struct {
|
||||
data []byte
|
||||
folder string
|
||||
name string
|
||||
offset int64
|
||||
size int
|
||||
hash []byte
|
||||
flags uint32
|
||||
options []Option
|
||||
closedCh chan bool
|
||||
data []byte
|
||||
folder string
|
||||
name string
|
||||
offset int64
|
||||
size int
|
||||
hash []byte
|
||||
flags uint32
|
||||
options []Option
|
||||
closedCh chan struct{}
|
||||
closedErr error
|
||||
}
|
||||
|
||||
func newTestModel() *TestModel {
|
||||
return &TestModel{
|
||||
closedCh: make(chan bool),
|
||||
closedCh: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,18 +45,19 @@ func (t *TestModel) Request(deviceID DeviceID, folder, name string, offset int64
|
||||
}
|
||||
|
||||
func (t *TestModel) Close(deviceID DeviceID, err error) {
|
||||
t.closedErr = err
|
||||
close(t.closedCh)
|
||||
}
|
||||
|
||||
func (t *TestModel) ClusterConfig(deviceID DeviceID, config ClusterConfigMessage) {
|
||||
}
|
||||
|
||||
func (t *TestModel) isClosed() bool {
|
||||
func (t *TestModel) closedError() error {
|
||||
select {
|
||||
case <-t.closedCh:
|
||||
return true
|
||||
return t.closedErr
|
||||
case <-time.After(1 * time.Second):
|
||||
return false // Timeout
|
||||
return nil // Timeout
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user