Patchwork [7,of,7] tests: mock getpid to reduce glob usage

login
register
mail settings
Submitter timeless@mozdev.org
Date Feb. 3, 2016, 9:40 p.m.
Message ID <ec8f94a8957cb7c521d9.1454535649@waste.org>
Download mbox | patch
Permalink /patch/12967/
State Superseded
Commit ac49ecb2a897f86b26037e22306549aa8addb640
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - Feb. 3, 2016, 9:40 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1454474224 0
#      Wed Feb 03 04:37:04 2016 +0000
# Node ID ec8f94a8957cb7c521d94c0a40c9b146083e21a2
# Parent  0594bc25250938518eaffe34d7a06b719e47cef5
tests: mock getpid to reduce glob usage

With util.getpid, it is now possible to define fixed pids.

Future iterations can define a map of pids on a locked
first come first serve basis to create a more realistic
harness, but for now this is good enough.

This applies to blackbox, but could apply to other
tests as well.

Patch

diff --git a/tests/mockblackbox.py b/tests/mockblackbox.py
--- a/tests/mockblackbox.py
+++ b/tests/mockblackbox.py
@@ -4,8 +4,11 @@ 
     return 0, 0
 def getuser():
     return 'bob'
+def getpid():
+    return 5000
 
 # mock the date and user apis so the output is always the same
 def uisetup(ui):
     util.makedate = makedate
     util.getuser = getuser
+    util.getpid = getpid
diff --git a/tests/test-blackbox.t b/tests/test-blackbox.t
--- a/tests/test-blackbox.t
+++ b/tests/test-blackbox.t
@@ -13,9 +13,9 @@ 
   $ echo a > a
   $ hg add a
   $ hg blackbox
-  1970/01/01 00:00:00 bob (*)> add a (glob)
-  1970/01/01 00:00:00 bob (*)> add a exited 0 after * seconds (glob)
-  1970/01/01 00:00:00 bob (*)> blackbox (glob)
+  1970/01/01 00:00:00 bob (5000)> add a
+  1970/01/01 00:00:00 bob (5000)> add a exited 0 after * seconds (glob)
+  1970/01/01 00:00:00 bob (5000)> blackbox
 
 incoming change tracking
 
@@ -45,11 +45,11 @@ 
   added 1 changesets with 1 changes to 1 files
   (run 'hg update' to get a working copy)
   $ hg blackbox -l 5
-  1970/01/01 00:00:00 bob (*)> updated served branch cache in * seconds (glob)
-  1970/01/01 00:00:00 bob (*)> wrote served branch cache with 1 labels and 2 nodes (glob)
-  1970/01/01 00:00:00 bob (*)> 1 incoming changes - new heads: d02f48003e62 (glob)
-  1970/01/01 00:00:00 bob (*)> pull exited 0 after * seconds (glob)
-  1970/01/01 00:00:00 bob (*)> blackbox -l 5 (glob)
+  1970/01/01 00:00:00 bob (5000)> updated served branch cache in * seconds (glob)
+  1970/01/01 00:00:00 bob (5000)> wrote served branch cache with 1 labels and 2 nodes
+  1970/01/01 00:00:00 bob (5000)> 1 incoming changes - new heads: d02f48003e62
+  1970/01/01 00:00:00 bob (5000)> pull exited 0 after * seconds (glob)
+  1970/01/01 00:00:00 bob (5000)> blackbox -l 5
 
 we must not cause a failure if we cannot write to the log
 
@@ -108,11 +108,11 @@ 
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   saved backup bundle to $TESTTMP/blackboxtest2/.hg/strip-backup/*-backup.hg (glob)
   $ hg blackbox -l 5
-  1970/01/01 00:00:00 bob (*)> saved backup bundle to $TESTTMP/blackboxtest2/.hg/strip-backup/*-backup.hg (glob)
-  1970/01/01 00:00:00 bob (*)> updated base branch cache in * seconds (glob)
-  1970/01/01 00:00:00 bob (*)> wrote base branch cache with 1 labels and 2 nodes (glob)
-  1970/01/01 00:00:00 bob (*)> strip tip exited 0 after * seconds (glob)
-  1970/01/01 00:00:00 bob (*)> blackbox -l 5 (glob)
+  1970/01/01 00:00:00 bob (5000)> saved backup bundle to $TESTTMP/blackboxtest2/.hg/strip-backup/*-backup.hg (glob)
+  1970/01/01 00:00:00 bob (5000)> updated base branch cache in * seconds (glob)
+  1970/01/01 00:00:00 bob (5000)> wrote base branch cache with 1 labels and 2 nodes
+  1970/01/01 00:00:00 bob (5000)> strip tip exited 0 after * seconds (glob)
+  1970/01/01 00:00:00 bob (5000)> blackbox -l 5
 
 extension and python hooks - use the eol extension for a pythonhook
 
@@ -124,11 +124,11 @@ 
   hooked
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg blackbox -l 5
-  1970/01/01 00:00:00 bob (*)> writing .hg/cache/tags2-visible with 0 tags (glob)
-  1970/01/01 00:00:00 bob (*)> pythonhook-preupdate: hgext.eol.preupdate finished in * seconds (glob)
-  1970/01/01 00:00:00 bob (*)> exthook-update: echo hooked finished in * seconds (glob)
-  1970/01/01 00:00:00 bob (*)> update exited 0 after * seconds (glob)
-  1970/01/01 00:00:00 bob (*)> blackbox -l 5 (glob)
+  1970/01/01 00:00:00 bob (5000)> writing .hg/cache/tags2-visible with 0 tags
+  1970/01/01 00:00:00 bob (5000)> pythonhook-preupdate: hgext.eol.preupdate finished in * seconds (glob)
+  1970/01/01 00:00:00 bob (5000)> exthook-update: echo hooked finished in * seconds (glob)
+  1970/01/01 00:00:00 bob (5000)> update exited 0 after * seconds (glob)
+  1970/01/01 00:00:00 bob (5000)> blackbox -l 5
 
 log rotation
 
@@ -149,7 +149,7 @@ 
   $ hg init blackboxtest3
   $ cd blackboxtest3
   $ hg blackbox
-  1970/01/01 00:00:00 bob (*)> blackbox (glob)
+  1970/01/01 00:00:00 bob (50000)> blackbox (glob)
   $ mv .hg/blackbox.log .hg/blackbox.log-
   $ mkdir .hg/blackbox.log
   $ perl -pne 'if (/test1/) {s/^/#/; next} if (/commit2/) { print qq{os.rmdir(".hg/blackbox.log")\nos.rename(".hg/blackbox.log-", ".hg/blackbox.log")\n} }' $TESTDIR/test-dispatch.py > ../test-dispatch.py
@@ -176,9 +176,9 @@ 
   
   result: None
   $ hg blackbox
-  1970/01/01 00:00:00 bob (*)> blackbox (glob)
-  1970/01/01 00:00:00 bob (*)> blackbox exited 0 after * seconds (glob)
-  1970/01/01 00:00:00 bob (*)> blackbox (glob)
+  1970/01/01 00:00:00 bob (5000)> blackbox
+  1970/01/01 00:00:00 bob (5000)> blackbox exited 0 after * seconds (glob)
+  1970/01/01 00:00:00 bob (5000)> blackbox
 
 cleanup
   $ cd ..