Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix: --wait flag in ipfs-cluster-ctl and WaitFor function #363

Merged
merged 4 commits into from
Mar 29, 2018
Merged

Conversation

hsanjuan
Copy link
Collaborator

@lanzafame this was very visibly not working when I tried it. Please test a bit better next time.

@hsanjuan hsanjuan self-assigned this Mar 28, 2018
@hsanjuan hsanjuan requested a review from lanzafame March 28, 2018 15:24
@ghost ghost added the status/in-progress In progress label Mar 28, 2018
@hsanjuan hsanjuan mentioned this pull request Mar 28, 2018
@lanzafame
Copy link
Contributor

@hsanjuan Agreed. Could you help me see where I went wrong with the following sharness tests, as they shouldn't have passed.

From sharness/t0030-ctl-pin.sh:

expecting success:
    cid=`docker exec ipfs sh -c "dd if=/dev/urandom bs=1024 count=2048 | ipfs add -q"`
    ipfs-cluster-ctl pin add --wait "$cid" | grep -q -i "PINNED" &&
    ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
    ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"

expecting success:
    cid=`ipfs-cluster-ctl --enc=json pin ls | jq -r ".[] | .cid" | head -1`
    ipfs-cluster-ctl pin rm --wait "$cid" | grep -q -i "UNPINNED" &&
    !(ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid") &&
    ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED"

expecting success:
    cid=`docker exec ipfs sh -c "dd if=/dev/urandom bs=1024 count=2048 | ipfs add -q"`
    ipfs-cluster-ctl pin add --wait --wait-timeout 2s "$cid" | grep -q -i "PINNED" &&
    ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
    ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"

expecting success:
    cid=`ipfs-cluster-ctl --enc=json pin ls | jq -r ".[] | .cid" | head -1`
    ipfs-cluster-ctl pin rm --wait --wait-timeout 2s "$cid" | grep -q -i "UNPINNED" &&
    !(ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid") &&
    ipfs-cluster-ctl status "$cid" | grep -q -i "UNPINNED"

Also, api/rest/client/methods_test.go is failing to build because a reference to test.SlowCid which doesn't exist?

}

if status.Cid == nil { // no status from "wait"
time.Sleep(1000 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/1000*time.Millisecond/1*time.Second

waitAndFormatStatusResponse(
c,
c.Bool("wait"),
c.Bool("no-status"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird that waitAndFormatStatusResponse would handle the --no-status flag. Maybe handleResponseFormatFlags would be a better name and then retrieve wait and no-status from *cli.Context. Or the other way, could be to handle no-status outside of waitAndFormatStatusResponse. Not sure which would be better? @hsanjuan

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did the first

tapi.SetClient(rpcC)

testF := func(t *testing.T, c *Client) {
ci, _ := cid.Decode(test.SlowCid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test.SlowCid doesn't exist. Related question, where do the test.TestCid1, etc, come from when running the tests?

@@ -251,12 +252,10 @@ func (sf *statusFilter) filter(ctx context.Context, fp StatusFilterParams) {
return
}

sf.Out <- gblPinInfo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return status, nil
}
case st, ok := <-sf.Out:
if ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplified to:

if !ok {
    return status, nil
}
status = st

@hsanjuan
Copy link
Collaborator Author

@hsanjuan Agreed. Could you help me see where I went wrong with the following sharness tests, as they shouldn't have passed.

The first case in a switch was case !c.Bool("no-status"). Since that flag is set to false by default, it waited 1 second and print a status (in which everything was pinned already because it's fast enough). So the output would look like you had been waiting.

While those tests verify that the flags are actually valid and usable and that we can call the command with them, they don't fully verify the behavior. I haven't come up with a straightforward way to fully verify --wait with sharness so I left those as they are. They still will catch some errors.

@hsanjuan hsanjuan requested a review from lanzafame March 29, 2018 08:41
@coveralls
Copy link

Coverage Status

Coverage increased (+0.8%) to 67.202% when pulling 63509cf on fix/wait into f8acd4f on master.

Copy link
Contributor

@lanzafame lanzafame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just two last nitpicks sorry.

c *cli.Context,
ci *cid.Cid,
target api.TrackerStatus,
timeout time.Duration,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could access the timeout value via cli.Context?

return
}

if status.Cid == nil { // no status from "wait"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this go before the no-status check as it is related to the wait flag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It couldn't, because I don't need to fetch a status if no-status is set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does having --wait and --no-status set at the same time make sense though?

Copy link
Contributor

@lanzafame lanzafame Mar 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry nvm, I was totally not understanding that correctly

The --wait flag was being completely ignored unless --no-status was passed
too, which makes no sense because then it would print the wait status.

This waits when --wait and prints the status when --no-status is not passed.

If we have been waiting, the status comes from that. Otherwise we request it.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
Since no-one is reading sf.Out, sending blocks and everything hangs.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
Actually test that WaitFor waits

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
Copy link
Contributor

@lanzafame lanzafame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hsanjuan hsanjuan merged commit 9c5ca7c into master Mar 29, 2018
@ghost ghost removed the status/in-progress In progress label Mar 29, 2018
@hsanjuan hsanjuan deleted the fix/wait branch March 29, 2018 10:00
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants