← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/testrunner-uuid into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/testrunner-uuid into lp:launchpad.

Commit message:
Generate LP_TEST_INSTANCE based on a UUID rather than the process ID.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/testrunner-uuid/+merge/272942

When running tests in parallel, it's possible (and in some setups quite probable) for various LXC containers to end up with the same process IDs for bin/test.  To avoid problems caused by this, generate LP_TEST_INSTANCE based on a UUID (replacing "-" with "_" so that it can form part of a valid database name) rather than the process ID.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/testrunner-uuid into lp:launchpad.
=== modified file 'lib/lp/testing/layers.py'
--- lib/lp/testing/layers.py	2013-08-14 11:15:51 +0000
+++ lib/lp/testing/layers.py	2015-09-30 16:07:46 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Layers used by Launchpad tests.
@@ -70,6 +70,7 @@
     TestResult,
     )
 from urllib import urlopen
+import uuid
 
 from fixtures import (
     Fixture,
@@ -329,7 +330,7 @@
         # We can only do unique test allocation and parallelisation if
         # LP_PERSISTENT_TEST_SERVICES is off.
         if not BaseLayer.persist_test_services:
-            test_instance = str(os.getpid())
+            test_instance = str(uuid.uuid1()).replace('-', '_')
             os.environ['LP_TEST_INSTANCE'] = test_instance
             cls.fixture.addCleanup(os.environ.pop, 'LP_TEST_INSTANCE', '')
             # Kill any Memcached or Librarian left running from a previous

=== modified file 'lib/lp/testing/tests/test_layers_functional.py'
--- lib/lp/testing/tests/test_layers_functional.py	2013-06-21 01:55:44 +0000
+++ lib/lp/testing/tests/test_layers_functional.py	2015-09-30 16:07:46 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 from __future__ import with_statement
@@ -17,6 +17,7 @@
 import signal
 import smtplib
 from urllib import urlopen
+import uuid
 
 from amqplib import client_0_8 as amqp
 from fixtures import (
@@ -113,9 +114,10 @@
     def test_allocates_LP_TEST_INSTANCE(self):
         self.useFixture(BaseLayerIsolator())
         with LayerFixture(BaseLayer):
-            self.assertEqual(
-                str(os.getpid()),
-                os.environ.get('LP_TEST_INSTANCE'))
+            instance_uuid = uuid.UUID(
+                os.environ['LP_TEST_INSTANCE'].replace('_', '-'))
+            self.assertEqual(uuid.RFC_4122, instance_uuid.variant)
+            self.assertEqual(1, instance_uuid.version)
         self.assertEqual(None, os.environ.get('LP_TEST_INSTANCE'))
 
     def test_persist_test_services_disables_LP_TEST_INSTANCE(self):

=== modified file 'lib/lp/testing/tests/test_pgsql.py'
--- lib/lp/testing/tests/test_pgsql.py	2012-04-19 10:53:54 +0000
+++ lib/lp/testing/tests/test_pgsql.py	2015-09-30 16:07:46 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 import os
@@ -8,6 +8,7 @@
     TestWithFixtures,
     )
 import testtools
+import uuid
 
 from lp.services.config import dbconfig
 from lp.services.config.fixture import ConfigUseFixture
@@ -36,7 +37,12 @@
         BaseLayer.setUp()
         self.addCleanup(BaseLayer.tearDown)
         fixture = PgTestSetup(dbname=PgTestSetup.dynamic)
-        expected_name = "%s_%d" % (PgTestSetup.dbname, os.getpid())
+        instance_uuid = uuid.UUID(
+            os.environ['LP_TEST_INSTANCE'].replace('_', '-'))
+        self.assertEqual(uuid.RFC_4122, instance_uuid.variant)
+        self.assertEqual(1, instance_uuid.version)
+        expected_name = "%s_%s" % (
+            PgTestSetup.dbname, str(instance_uuid).replace('-', '_'))
         self.assertDBName(expected_name, fixture)
 
     def test_db_naming_without_LP_TEST_INSTANCE_is_static(self):


Follow ups