Skip to content

Commit

Permalink
test/supernode_client/main: fix t.Fatal in a goroutine
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
chriscool committed Dec 14, 2015
1 parent f41801c commit 57c4188
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions test/supernode_client/main.go
Original file line number Diff line number Diff line change
@@ -142,24 +142,34 @@ func sizeOfIthFile(i int64) int64 {
}

func runFileAddingWorker(n *core.IpfsNode) error {
errs := make(chan error)
go func() {
var i int64
for i = 1; i < math.MaxInt32; i++ {
piper, pipew := io.Pipe()
go func() {
defer pipew.Close()
if err := random.WritePseudoRandomBytes(sizeOfIthFile(i), pipew, *seed); err != nil {
log.Fatal(err)
errs <- err
}
}()
k, err := coreunix.Add(n, piper)
if err != nil {
log.Fatal(err)
errs <- err
}
log.Println("added file", "seed", *seed, "#", i, "key", k, "size", unit.Information(sizeOfIthFile(i)))
time.Sleep(1 * time.Second)
}
}()

var i int64
for i = 0; i < math.MaxInt32; i++ {
err := <-errs
if err != nil {
log.Fatal(err)
}
}

return nil
}

@@ -180,18 +190,20 @@ func runFileCattingWorker(ctx context.Context, n *core.IpfsNode) error {
return err
}

errs := make(chan error)

go func() {
defer dummy.Close()
var i int64 = 1
for {
buf := new(bytes.Buffer)
if err := random.WritePseudoRandomBytes(sizeOfIthFile(i), buf, *seed); err != nil {
log.Fatal(err)
errs <- err
}
// add to a dummy node to discover the key
k, err := coreunix.Add(dummy, bytes.NewReader(buf.Bytes()))
if err != nil {
log.Fatal(err)
errs <- err
}
e := elog.EventBegin(ctx, "cat", logging.LoggableF(func() map[string]interface{} {
return map[string]interface{}{
@@ -212,6 +224,12 @@ func runFileCattingWorker(ctx context.Context, n *core.IpfsNode) error {
time.Sleep(time.Second)
}
}()

err = <- errs
if err != nil {
log.Fatal(err)
}

return nil
}

0 comments on commit 57c4188

Please sign in to comment.