cmd/swarm/swarm-smoke: addressed PR comments

This commit is contained in:
Fabio Barone 2019-02-15 17:41:17 -05:00
parent 30915726d6
commit dcdff86b8e
2 changed files with 23 additions and 19 deletions

View file

@ -37,15 +37,16 @@ var (
)
var (
allhosts string
hosts []string
filesize int
syncDelay int
httpPort int
wsPort int
verbosity int
timeout int
single bool
allhosts string
hosts []string
filesize int
syncDelay int
httpPort int
wsPort int
verbosity int
timeout int
single bool
getAllRefsTimeout int
)
func main() {
@ -102,6 +103,12 @@ func main() {
Usage: "whether to fetch content from a single node or from all nodes",
Destination: &single,
},
cli.IntFlag{
Name: "refs-timeout",
Value: 5,
Usage: "timeout in seconds to wait for GetAllReferences to return",
Destination: &getAllRefsTimeout,
},
}
app.Flags = append(app.Flags, []cli.Flag{

View file

@ -55,13 +55,14 @@ func uploadAndSyncCmd(ctx *cli.Context, tuid string) error {
case <-time.After(time.Duration(timeout) * time.Second):
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.timeout", commandName), nil).Inc(1)
e := fmt.Errorf("timeout after %v sec", timeout)
// trigger debug functionality on randomBytes
err := triggerChunkDebug(randomBytes)
err := triggerChunkDebug(randomBytes[:])
if err != nil {
log.Error("test timed out and triggerChunkDebug also produced error", "err", err)
e = fmt.Errorf("%v; triggerChunkDebug failed: %v", e, err)
}
return fmt.Errorf("timeout after %v sec", timeout)
return e
}
}
@ -72,6 +73,7 @@ func triggerChunkDebug(testData []byte) error {
if err != nil {
return err
}
log.Trace("All references retrieved")
// has-chunks
for _, host := range hosts {
@ -115,16 +117,11 @@ func getAllRefs(testData []byte) (storage.AddressCollection, error) {
if err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(getAllRefsTimeout)*time.Second)
defer cancel()
reader := bytes.NewReader(testData)
addrs, err := fileStore.GetAllReferences(ctx, reader, false)
if err != nil {
return nil, err
}
log.Trace("All references retrieved")
return addrs, err
return fileStore.GetAllReferences(ctx, reader, false)
}
func uplaodAndSync(c *cli.Context, randomBytes []byte, tuid string) error {