Skip to contentSkip to conversation

git-p4: ticket expiry test: use a fake p4 to avoid use of 'sleep'

PATCH In review Luke Diamand 3 participants 4 messages Feb 8, 2019 – Feb 9, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 git-p4: ticket expiry test: use a fake p4 to avoid use of 'sleep'

From: Luke Diamand <[email protected]>

This tests for p4 ticket expiry by creating a ticket, and then waiting long enough for the ticket to nearly expire. However, this is unreliable.

Instead, create a 'fake' p4 which returns expiry times under the control of the test script, and forwards other commands to the real p4 executable.

---
 t/t9833-errors.sh | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)
t/t9833-errors.sh +22 -20
index 277d347012..9d7cb5b35b 100755
@@ -45,30 +45,32 @@ test_expect_success 'ticket logged out' '
 	)
 '
 
-test_expect_success 'create group with short ticket expiry' '
-	P4TICKETS="$cli/tickets" &&
-	echo "newpassword" | p4 login &&
-	p4_add_user short_expiry_user &&
-	p4 -u short_expiry_user passwd -P password &&
-	p4 group -i <<-EOF &&
-	Group: testgroup
-	Timeout: 3
-	Users: short_expiry_user
-	EOF
-
-	p4 users | grep short_expiry_user
-'
+# create a fake version of "p4" which returns a TicketExpiration based
+# on $EXPIRY, for testing login expiration
+create_fake_p4() {
+	(
+		cd "$git" && mkdir expire-p4 &&
+		cat >>expire-p4/p4 <<-EOF &&
+		#!/usr/bin/python
+		import marshal, os, subprocess, sys
+		if "login" in sys.argv:
+		    marshal.dump({"foo" : "bar", "code" : "stat", "TicketExpiration" : os.environ["EXPIRY"]}, sys.stdout)
+		else:
+		    subprocess.check_call([os.environ["P4"]] + sys.argv[1:])
+		EOF
+		chmod 0755 expire-p4/p4
+	)
+}
 
 test_expect_success 'git operation with expired ticket' '
-	P4TICKETS="$cli/tickets" &&
-	P4USER=short_expiry_user &&
-	echo "password" | p4 login &&
+	create_fake_p4 &&
+	echo "newpassword" | p4 login &&
 	(
 		cd "$git" &&
-		git p4 sync &&
-		sleep 5 &&
-		test_must_fail git p4 sync 2>errmsg &&
-		grep "failure accessing depot" errmsg
+		P4=$(command -v p4) && export P4 &&
+		EXPIRY=3600 PATH=$PWD/expire-p4:$PATH git p4 sync &&
+		EXPIRY=1 PATH=$PWD/expire-p4:$PATH test_must_fail git p4 sync -v 2>errmsg &&
+		grep "failure accessing depot.*expires in 1 second" errmsg
 	)
 '
 
Signature · 1 line
2.20.1.612.g17ebf93fb6.dirty
#1 lore raw

t/t9833-errors.sh test_expect_success 'ticket logged out' ' · line 54

Quoted 7 lines · Luke Diamand
t/t9833-errors.sh +7 -0
+# create a fake version of "p4" which returns a TicketExpiration based
+# on $EXPIRY, for testing login expiration
+create_fake_p4() {
+	(
+		cd "$git" && mkdir expire-p4 &&
+		cat >>expire-p4/p4 <<-EOF &&
+		#!/usr/bin/python

I think this should be $PYTHON_PATH.

Quoted 32 lines
t/t9833-errors.sh +15 -7
+		import marshal, os, subprocess, sys
+		if "login" in sys.argv:
+		    marshal.dump({"foo" : "bar", "code" : "stat", "TicketExpiration" : os.environ["EXPIRY"]}, sys.stdout)
+		else:
+		    subprocess.check_call([os.environ["P4"]] + sys.argv[1:])
+		EOF
+		chmod 0755 expire-p4/p4
+	)
+}
 
 test_expect_success 'git operation with expired ticket' '
-	P4TICKETS="$cli/tickets" &&
-	P4USER=short_expiry_user &&
-	echo "password" | p4 login &&
+	create_fake_p4 &&
+	echo "newpassword" | p4 login &&
 	(
 		cd "$git" &&
-		git p4 sync &&
-		sleep 5 &&
-		test_must_fail git p4 sync 2>errmsg &&
-		grep "failure accessing depot" errmsg
+		P4=$(command -v p4) && export P4 &&
+		EXPIRY=3600 PATH=$PWD/expire-p4:$PATH git p4 sync &&
+		EXPIRY=1 PATH=$PWD/expire-p4:$PATH test_must_fail git p4 sync -v 2>errmsg &&
+		grep "failure accessing depot.*expires in 1 second" errmsg
 	)
 '
Signature · 2 lines
-- 
2.20.1.612.g17ebf93fb6.dirty
#2 lore raw
Quoted 10 lines · SZEDER Gábor

t/t9833-errors.sh test_expect_success 'ticket logged out' ' · line 54

Quoted 7 lines · Luke Diamand
t/t9833-errors.sh +7 -0
+# create a fake version of "p4" which returns a TicketExpiration based
+# on $EXPIRY, for testing login expiration
+create_fake_p4() {
+	(
+		cd "$git" && mkdir expire-p4 &&
+		cat >>expire-p4/p4 <<-EOF &&
+		#!/usr/bin/python

I think this should be $PYTHON_PATH.

OK.

Luke, I think our mails / work crossed and the tip of 'master' already has a removal. Please make this into a separate patch that adds (or, resurrects with an improved version) the test for the next cycle.

Thanks.

#3 lore raw
Quoted 14 lines · Junio C Hamano
Quoted 10 lines · SZEDER Gábor

t/t9833-errors.sh test_expect_success 'ticket logged out' ' · line 54

Quoted 7 lines · Luke Diamand
t/t9833-errors.sh +7 -0
+# create a fake version of "p4" which returns a TicketExpiration based
+# on $EXPIRY, for testing login expiration
+create_fake_p4() {
+    (
+            cd "$git" && mkdir expire-p4 &&
+            cat >>expire-p4/p4 <<-EOF &&
+            #!/usr/bin/python

I think this should be $PYTHON_PATH.

Quoted 6 lines

OK.

Luke, I think our mails / work crossed and the tip of 'master' already has a removal. Please make this into a separate patch that adds (or, resurrects with an improved version) the test for the next cycle.

OK, thanks!