{"thread":{"id":"50440","subject":"[PATCHv2] git-p4: ticket expiry test: use a fake p4 to avoid use of 'sleep'","startedAt":"2019-02-08T19:03:35Z","lastAt":"2019-02-09T19:26:38Z","messageCount":4,"participants":["Luke Diamand","SZEDER Gábor","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"368858","messageId":"20190208190231.8134-1-luke@diamand.org","threadId":"50440","inReplyTo":null,"subject":"[PATCHv2] git-p4: ticket expiry test: use a fake p4 to avoid use of 'sleep'","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2019-02-08T19:02:31Z","receivedAt":"2019-02-08T19:03:35Z","isPatch":false,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"From: Luke Diamand <ldiamand@roku.com>\n\nThis tests for p4 ticket expiry by creating a ticket, and then waiting\nlong enough for the ticket to nearly expire. However, this is\nunreliable.\n\nInstead, create a 'fake' p4 which returns expiry times under the\ncontrol of the test script, and forwards other commands to the\nreal p4 executable.\n\nSigned-off-by: Luke Diamand <luke@diamand.org>\n---\n t/t9833-errors.sh | 42 ++++++++++++++++++++++--------------------\n 1 file changed, 22 insertions(+), 20 deletions(-)\n\ndiff --git a/t/t9833-errors.sh b/t/t9833-errors.sh\nindex 277d347012..9d7cb5b35b 100755\n--- a/t/t9833-errors.sh\n+++ b/t/t9833-errors.sh\n@@ -45,30 +45,32 @@ test_expect_success 'ticket logged out' '\n \t)\n '\n \n-test_expect_success 'create group with short ticket expiry' '\n-\tP4TICKETS=\"$cli/tickets\" &&\n-\techo \"newpassword\" | p4 login &&\n-\tp4_add_user short_expiry_user &&\n-\tp4 -u short_expiry_user passwd -P password &&\n-\tp4 group -i <<-EOF &&\n-\tGroup: testgroup\n-\tTimeout: 3\n-\tUsers: short_expiry_user\n-\tEOF\n-\n-\tp4 users | grep short_expiry_user\n-'\n+# create a fake version of \"p4\" which returns a TicketExpiration based\n+# on $EXPIRY, for testing login expiration\n+create_fake_p4() {\n+\t(\n+\t\tcd \"$git\" && mkdir expire-p4 &&\n+\t\tcat >>expire-p4/p4 <<-EOF &&\n+\t\t#!/usr/bin/python\n+\t\timport marshal, os, subprocess, sys\n+\t\tif \"login\" in sys.argv:\n+\t\t    marshal.dump({\"foo\" : \"bar\", \"code\" : \"stat\", \"TicketExpiration\" : os.environ[\"EXPIRY\"]}, sys.stdout)\n+\t\telse:\n+\t\t    subprocess.check_call([os.environ[\"P4\"]] + sys.argv[1:])\n+\t\tEOF\n+\t\tchmod 0755 expire-p4/p4\n+\t)\n+}\n \n test_expect_success 'git operation with expired ticket' '\n-\tP4TICKETS=\"$cli/tickets\" &&\n-\tP4USER=short_expiry_user &&\n-\techo \"password\" | p4 login &&\n+\tcreate_fake_p4 &&\n+\techo \"newpassword\" | p4 login &&\n \t(\n \t\tcd \"$git\" &&\n-\t\tgit p4 sync &&\n-\t\tsleep 5 &&\n-\t\ttest_must_fail git p4 sync 2>errmsg &&\n-\t\tgrep \"failure accessing depot\" errmsg\n+\t\tP4=$(command -v p4) && export P4 &&\n+\t\tEXPIRY=3600 PATH=$PWD/expire-p4:$PATH git p4 sync &&\n+\t\tEXPIRY=1 PATH=$PWD/expire-p4:$PATH test_must_fail git p4 sync -v 2>errmsg &&\n+\t\tgrep \"failure accessing depot.*expires in 1 second\" errmsg\n \t)\n '\n \n-- \n2.20.1.612.g17ebf93fb6.dirty\n\n"},{"id":"368876","messageId":"20190208201445.GB10587@szeder.dev","threadId":"50440","inReplyTo":"20190208190231.8134-1-luke@diamand.org","subject":"Re: [PATCHv2] git-p4: ticket expiry test: use a fake p4 to avoid use of 'sleep'","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-02-08T20:14:45Z","receivedAt":"2019-02-08T20:14:50Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Feb 08, 2019 at 07:02:31PM +0000, Luke Diamand wrote:\n> +# create a fake version of \"p4\" which returns a TicketExpiration based\n> +# on $EXPIRY, for testing login expiration\n> +create_fake_p4() {\n> +\t(\n> +\t\tcd \"$git\" && mkdir expire-p4 &&\n> +\t\tcat >>expire-p4/p4 <<-EOF &&\n> +\t\t#!/usr/bin/python\n\nI think this should be $PYTHON_PATH.\n\n> +\t\timport marshal, os, subprocess, sys\n> +\t\tif \"login\" in sys.argv:\n> +\t\t    marshal.dump({\"foo\" : \"bar\", \"code\" : \"stat\", \"TicketExpiration\" : os.environ[\"EXPIRY\"]}, sys.stdout)\n> +\t\telse:\n> +\t\t    subprocess.check_call([os.environ[\"P4\"]] + sys.argv[1:])\n> +\t\tEOF\n> +\t\tchmod 0755 expire-p4/p4\n> +\t)\n> +}\n>  \n>  test_expect_success 'git operation with expired ticket' '\n> -\tP4TICKETS=\"$cli/tickets\" &&\n> -\tP4USER=short_expiry_user &&\n> -\techo \"password\" | p4 login &&\n> +\tcreate_fake_p4 &&\n> +\techo \"newpassword\" | p4 login &&\n>  \t(\n>  \t\tcd \"$git\" &&\n> -\t\tgit p4 sync &&\n> -\t\tsleep 5 &&\n> -\t\ttest_must_fail git p4 sync 2>errmsg &&\n> -\t\tgrep \"failure accessing depot\" errmsg\n> +\t\tP4=$(command -v p4) && export P4 &&\n> +\t\tEXPIRY=3600 PATH=$PWD/expire-p4:$PATH git p4 sync &&\n> +\t\tEXPIRY=1 PATH=$PWD/expire-p4:$PATH test_must_fail git p4 sync -v 2>errmsg &&\n> +\t\tgrep \"failure accessing depot.*expires in 1 second\" errmsg\n>  \t)\n>  '\n>  \n> -- \n> 2.20.1.612.g17ebf93fb6.dirty\n> \n"},{"id":"368929","messageId":"xmqq4l9ckfab.fsf@gitster-ct.c.googlers.com","threadId":"50440","inReplyTo":"20190208201445.GB10587@szeder.dev","subject":"Re: [PATCHv2] git-p4: ticket expiry test: use a fake p4 to avoid use of 'sleep'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-02-09T18:06:20Z","receivedAt":"2019-02-09T18:06:27Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder.dev@gmail.com> writes:\n\n> On Fri, Feb 08, 2019 at 07:02:31PM +0000, Luke Diamand wrote:\n>> +# create a fake version of \"p4\" which returns a TicketExpiration based\n>> +# on $EXPIRY, for testing login expiration\n>> +create_fake_p4() {\n>> +\t(\n>> +\t\tcd \"$git\" && mkdir expire-p4 &&\n>> +\t\tcat >>expire-p4/p4 <<-EOF &&\n>> +\t\t#!/usr/bin/python\n>\n> I think this should be $PYTHON_PATH.\n\nOK.\n\nLuke, I think our mails / work crossed and the tip of 'master'\nalready has a removal.  Please make this into a separate patch that\nadds (or, resurrects with an improved version) the test for the next\ncycle.\n\nThanks.\n"},{"id":"368940","messageId":"CAE5ih7_UTONAK5YCj_xYAa-d3zts8RUSkaAFtixa9exnxG8acg@mail.gmail.com","threadId":"50440","inReplyTo":"xmqq4l9ckfab.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCHv2] git-p4: ticket expiry test: use a fake p4 to avoid use of 'sleep'","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2019-02-09T19:26:24Z","receivedAt":"2019-02-09T19:26:38Z","isPatch":false,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On Sat, 9 Feb 2019 at 18:06, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> SZEDER Gábor <szeder.dev@gmail.com> writes:\n>\n> > On Fri, Feb 08, 2019 at 07:02:31PM +0000, Luke Diamand wrote:\n> >> +# create a fake version of \"p4\" which returns a TicketExpiration based\n> >> +# on $EXPIRY, for testing login expiration\n> >> +create_fake_p4() {\n> >> +    (\n> >> +            cd \"$git\" && mkdir expire-p4 &&\n> >> +            cat >>expire-p4/p4 <<-EOF &&\n> >> +            #!/usr/bin/python\n> >\n> > I think this should be $PYTHON_PATH.\n>\n> OK.\n>\n> Luke, I think our mails / work crossed and the tip of 'master'\n> already has a removal.  Please make this into a separate patch that\n> adds (or, resurrects with an improved version) the test for the next\n> cycle.\n\nOK, thanks!\n"}]}