Improve protocol tests, close handling

This commit is contained in:
Jakob Borg
2016-01-12 09:19:44 +01:00
parent 7427b9de35
commit 9595687bce
3 changed files with 25 additions and 21 deletions

View File

@@ -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
}
}