Fix tests for >1 CPU (fixes #99)

This commit is contained in:
Jakob Borg
2014-03-22 17:06:15 +01:00
parent 68d9454bc4
commit 513100bb92
3 changed files with 42 additions and 25 deletions

View File

@@ -1,14 +1,23 @@
package protocol
import "io"
import (
"io"
"time"
)
type TestModel struct {
data []byte
repo string
name string
offset int64
size int
closed bool
data []byte
repo string
name string
offset int64
size int
closedCh chan bool
}
func newTestModel() *TestModel {
return &TestModel{
closedCh: make(chan bool),
}
}
func (t *TestModel) Index(nodeID string, files []FileInfo) {
@@ -26,7 +35,16 @@ func (t *TestModel) Request(nodeID, repo, name string, offset int64, size int) (
}
func (t *TestModel) Close(nodeID string, err error) {
t.closed = true
close(t.closedCh)
}
func (t *TestModel) isClosed() bool {
select {
case <-t.closedCh:
return true
case <-time.After(1 * time.Second):
return false // Timeout
}
}
type ErrPipe struct {