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

@ -46,6 +46,7 @@ var (
verbosity int verbosity int
timeout int timeout int
single bool single bool
getAllRefsTimeout int
) )
func main() { func main() {
@ -102,6 +103,12 @@ func main() {
Usage: "whether to fetch content from a single node or from all nodes", Usage: "whether to fetch content from a single node or from all nodes",
Destination: &single, 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{ 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): case <-time.After(time.Duration(timeout) * time.Second):
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.timeout", commandName), nil).Inc(1) metrics.GetOrRegisterCounter(fmt.Sprintf("%s.timeout", commandName), nil).Inc(1)
e := fmt.Errorf("timeout after %v sec", timeout)
// trigger debug functionality on randomBytes // trigger debug functionality on randomBytes
err := triggerChunkDebug(randomBytes) err := triggerChunkDebug(randomBytes[:])
if err != nil { 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 { if err != nil {
return err return err
} }
log.Trace("All references retrieved")
// has-chunks // has-chunks
for _, host := range hosts { for _, host := range hosts {
@ -115,16 +117,11 @@ func getAllRefs(testData []byte) (storage.AddressCollection, error) {
if err != nil { if err != nil {
return nil, err 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() defer cancel()
reader := bytes.NewReader(testData) reader := bytes.NewReader(testData)
addrs, err := fileStore.GetAllReferences(ctx, reader, false) return fileStore.GetAllReferences(ctx, reader, false)
if err != nil {
return nil, err
}
log.Trace("All references retrieved")
return addrs, err
} }
func uplaodAndSync(c *cli.Context, randomBytes []byte, tuid string) error { func uplaodAndSync(c *cli.Context, randomBytes []byte, tuid string) error {