diff options
author | Benoit Foucher <benoit@zeroc.com> | 2017-01-05 12:17:23 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2017-01-05 12:17:23 +0100 |
commit | 3cbf6bc85466e5a4aa1be504e6e67eaa8bf0f186 (patch) | |
tree | b710c6b76aff8a67a95425894f7796b8f58d3657 | |
parent | Added workaround for running Safari tests with Jenkins (diff) | |
download | ice-3cbf6bc85466e5a4aa1be504e6e67eaa8bf0f186.tar.bz2 ice-3cbf6bc85466e5a4aa1be504e6e67eaa8bf0f186.tar.xz ice-3cbf6bc85466e5a4aa1be504e6e67eaa8bf0f186.zip |
Thread safety fixes for tests scripts
-rw-r--r-- | cpp/test/IceGrid/admin/test.py | 196 | ||||
-rw-r--r-- | cpp/test/IceGrid/fileLock/test.py | 2 | ||||
-rw-r--r-- | cpp/test/IceStorm/federation2/test.py | 4 | ||||
-rw-r--r-- | cpp/test/IceStorm/rep1/test.py | 4 | ||||
-rw-r--r-- | cpp/test/IceStorm/repstress/test.py | 16 | ||||
-rw-r--r-- | cpp/test/Slice/errorDetection/test.py | 2 | ||||
-rw-r--r-- | scripts/IceGridUtil.py | 2 | ||||
-rw-r--r-- | scripts/IceStormUtil.py | 2 | ||||
-rw-r--r-- | scripts/LocalDriver.py | 3 | ||||
-rw-r--r-- | scripts/Util.py | 77 | ||||
-rw-r--r-- | scripts/tests/Slice/generation.py | 2 |
11 files changed, 157 insertions, 153 deletions
diff --git a/cpp/test/IceGrid/admin/test.py b/cpp/test/IceGrid/admin/test.py index 0d851f49cd1..58bd2be8375 100644 --- a/cpp/test/IceGrid/admin/test.py +++ b/cpp/test/IceGrid/admin/test.py @@ -21,19 +21,19 @@ class IceGridAdminTestCase(IceGridTestCase): admin=IceGridAdmin() admin.start(current) - admin.expect('>>> ') - admin.sendline("server list") - admin.expect('>>> ') - admin.sendline('exit') + admin.expect(current, '>>> ') + admin.sendline(current, "server list") + admin.expect(current, '>>> ') + admin.sendline(current, 'exit') admin.stop(current, True) defaultRouterProps = { "Ice.Default.Router" : self.glacier2router.getClientProxy(current) } admin.start(current, props=defaultRouterProps) - admin.expect('>>> ') - admin.sendline("server list") - admin.expect('>>> ') - admin.sendline('exit') + admin.expect(current, '>>> ') + admin.sendline(current, "server list") + admin.expect(current, '>>> ') + admin.sendline(current, 'exit') admin.stop(current, True) current.writeln("ok") @@ -44,18 +44,18 @@ class IceGridAdminTestCase(IceGridTestCase): # Direct registry connection with SSL admin.start(current, args=["--ssl"]) - admin.expect('>>> ') - admin.sendline("server list") - admin.expect('>>> ') - admin.sendline('exit') + admin.expect(current, '>>> ') + admin.sendline(current, "server list") + admin.expect(current, '>>> ') + admin.sendline(current, 'exit') admin.stop(current, True) # Glacier2 connection with username/password admin.start(current, args=["--ssl"], props=defaultRouterProps) - admin.expect('>>> ') - admin.sendline("server list") - admin.expect('>>> ') - admin.sendline('exit') + admin.expect(current, '>>> ') + admin.sendline(current, "server list") + admin.expect(current, '>>> ') + admin.sendline(current, 'exit') admin.stop(current, True) current.writeln("ok") @@ -65,88 +65,88 @@ class IceGridAdminTestCase(IceGridTestCase): try: serverDir = current.getBuildDir("server") - admin.expect('>>> ') - admin.sendline('application add application.xml server.dir=%s' % serverDir) - admin.expect('>>> ') - admin.sendline('application list') - admin.expect('Test') - admin.sendline('application describe Test') - admin.expect('application `Test\'') - admin.expect('\{.*\}') - admin.expect('>>> ') - admin.sendline('application diff application.xml server.dir=%s' % serverDir) - admin.expect('application `Test\'\n\{.*\}') - admin.expect('>>> ') - admin.sendline('application update application.xml server.dir=%s' % serverDir) - admin.expect('>>> ') - admin.sendline('application patch Test') - admin.expect('>>> ') - admin.sendline('server list') - admin.expect('server') - admin.expect('>>> ') - admin.sendline('server describe server') - admin.expect('server `server\'\n\{.*\}') - admin.expect('>>> ') - admin.sendline('server start server') - admin.expect('>>> ') - admin.sendline('server state server') - admin.expect('^active \(.*\)') - admin.expect('>>> ') - admin.sendline('server pid server') - admin.expect('[0-9]+') - admin.expect('>>> ') - admin.sendline('server properties server') - admin.expect('>>> ') - admin.sendline('server property server Ice.Admin.ServerId') - admin.expect("^server") - admin.expect('>>> ') - admin.sendline('server patch server') - admin.expect('>>> ') - admin.sendline('server disable server') - admin.expect('>>> ') - admin.sendline('server enable server') - admin.expect('>>> ') - admin.sendline('adapter list') - admin.expect('TestAdapter') - admin.expect('>>> ') - admin.sendline('adapter endpoints TestAdapter') - admin.expect(['tcp', 'ssl', 'ws', 'wss']) - admin.expect('>>> ') - admin.sendline('object list') - admin.expect('test') - admin.expect('>>> ') - admin.sendline('object describe') - admin.expect('proxy = `.*\' type = `.*\'') - admin.expect('>>> ') - admin.sendline('object find Test') - admin.expect('test') - admin.expect('>>> ') - admin.sendline('server stop server') - admin.expect('>>> ') - admin.sendline('application remove Test') - admin.expect('>>> ') - admin.sendline('registry list') - admin.expect('Master') - admin.expect('>>> ') - admin.sendline('registry ping Master') - admin.expect('registry is up') - admin.expect('>>> ') - admin.sendline('registry describe Master') - admin.expect('registry `Master\'\n{.*}') - admin.expect('>>> ') - admin.sendline('node list') - admin.expect('localnode') - admin.expect('>>> ') - admin.sendline('node describe localnode') - admin.expect('node `localnode\'\n{.*}') - admin.expect('>>> ') - admin.sendline('node load localnode') - admin.expect('load average.*\n') - admin.expect('>>> ') - admin.sendline('node ping localnode') - admin.expect('node is up') - admin.expect('>>> ') - admin.sendline('exit') + admin.expect(current, '>>> ') + admin.sendline(current, 'application add application.xml server.dir=%s' % serverDir) + admin.expect(current, '>>> ') + admin.sendline(current, 'application list') + admin.expect(current, 'Test') + admin.sendline(current, 'application describe Test') + admin.expect(current, 'application `Test\'') + admin.expect(current, '\{.*\}') + admin.expect(current, '>>> ') + admin.sendline(current, 'application diff application.xml server.dir=%s' % serverDir) + admin.expect(current, 'application `Test\'\n\{.*\}') + admin.expect(current, '>>> ') + admin.sendline(current, 'application update application.xml server.dir=%s' % serverDir) + admin.expect(current, '>>> ') + admin.sendline(current, 'application patch Test') + admin.expect(current, '>>> ') + admin.sendline(current, 'server list') + admin.expect(current, 'server') + admin.expect(current, '>>> ') + admin.sendline(current, 'server describe server') + admin.expect(current, 'server `server\'\n\{.*\}') + admin.expect(current, '>>> ') + admin.sendline(current, 'server start server') + admin.expect(current, '>>> ') + admin.sendline(current, 'server state server') + admin.expect(current, '^active \(.*\)') + admin.expect(current, '>>> ') + admin.sendline(current, 'server pid server') + admin.expect(current, '[0-9]+') + admin.expect(current, '>>> ') + admin.sendline(current, 'server properties server') + admin.expect(current, '>>> ') + admin.sendline(current, 'server property server Ice.Admin.ServerId') + admin.expect(current, "^server") + admin.expect(current, '>>> ') + admin.sendline(current, 'server patch server') + admin.expect(current, '>>> ') + admin.sendline(current, 'server disable server') + admin.expect(current, '>>> ') + admin.sendline(current, 'server enable server') + admin.expect(current, '>>> ') + admin.sendline(current, 'adapter list') + admin.expect(current, 'TestAdapter') + admin.expect(current, '>>> ') + admin.sendline(current, 'adapter endpoints TestAdapter') + admin.expect(current, ['tcp', 'ssl', 'ws', 'wss']) + admin.expect(current, '>>> ') + admin.sendline(current, 'object list') + admin.expect(current, 'test') + admin.expect(current, '>>> ') + admin.sendline(current, 'object describe') + admin.expect(current, 'proxy = `.*\' type = `.*\'') + admin.expect(current, '>>> ') + admin.sendline(current, 'object find Test') + admin.expect(current, 'test') + admin.expect(current, '>>> ') + admin.sendline(current, 'server stop server') + admin.expect(current, '>>> ') + admin.sendline(current, 'application remove Test') + admin.expect(current, '>>> ') + admin.sendline(current, 'registry list') + admin.expect(current, 'Master') + admin.expect(current, '>>> ') + admin.sendline(current, 'registry ping Master') + admin.expect(current, 'registry is up') + admin.expect(current, '>>> ') + admin.sendline(current, 'registry describe Master') + admin.expect(current, 'registry `Master\'\n{.*}') + admin.expect(current, '>>> ') + admin.sendline(current, 'node list') + admin.expect(current, 'localnode') + admin.expect(current, '>>> ') + admin.sendline(current, 'node describe localnode') + admin.expect(current, 'node `localnode\'\n{.*}') + admin.expect(current, '>>> ') + admin.sendline(current, 'node load localnode') + admin.expect(current, 'load average.*\n') + admin.expect(current, '>>> ') + admin.sendline(current, 'node ping localnode') + admin.expect(current, 'node is up') + admin.expect(current, '>>> ') + admin.sendline(current, 'exit') admin.stop(current, True) current.writeln("ok") except Exception as e: diff --git a/cpp/test/IceGrid/fileLock/test.py b/cpp/test/IceGrid/fileLock/test.py index 9a9ee60ece1..a15d0099bee 100644 --- a/cpp/test/IceGrid/fileLock/test.py +++ b/cpp/test/IceGrid/fileLock/test.py @@ -15,7 +15,7 @@ class IceGridAdminTestCase(IceGridTestCase): sys.stdout.write("testing IceGrid file lock... ") registry = IceGridRegistryMaster(portnum=25, readyCount=0, quiet=True); registry.start(current) - registry.expect(".*IceUtil::FileLockException.*") + registry.expect(current, ".*IceUtil::FileLockException.*") registry.stop(current, False) print("ok") diff --git a/cpp/test/IceStorm/federation2/test.py b/cpp/test/IceStorm/federation2/test.py index 5ac2f315555..213ab8d9e0c 100644 --- a/cpp/test/IceStorm/federation2/test.py +++ b/cpp/test/IceStorm/federation2/test.py @@ -93,7 +93,7 @@ class IceStormFederation2TestCase(IceStormTestCase): # Give some time for the output to be sent. time.sleep(2) - icestorm1[0].expect("topic.fed1.*subscriber offline") + icestorm1[0].expect(current, "topic.fed1.*subscriber offline") current.writeln("ok") current.write("starting downstream icestorm server... ") @@ -113,7 +113,7 @@ class IceStormFederation2TestCase(IceStormTestCase): current.writeln("ok") try: - icestorm1[0].expect("topic.fed1.*subscriber offline", timeout=1) + icestorm1[0].expect(current, "topic.fed1.*subscriber offline", timeout=1) assert False except Expect.TIMEOUT: pass diff --git a/cpp/test/IceStorm/rep1/test.py b/cpp/test/IceStorm/rep1/test.py index 7385a9d8d25..3c9ba79776b 100644 --- a/cpp/test/IceStorm/rep1/test.py +++ b/cpp/test/IceStorm/rep1/test.py @@ -62,7 +62,7 @@ class IceStormRep1TestCase(IceStormTestCase): readyCount=0, quiet=True) subscriber.run(current, exitstatus=1 if expect else 0) - checkExpect(subscriber.getOutput(), expect) + checkExpect(subscriber.getOutput(current), expect) def rununsub2(replica=None, expect=None): sub = Subscriber(exe="sub", @@ -77,7 +77,7 @@ class IceStormRep1TestCase(IceStormTestCase): # shouldn't get an AlreadySubscribedException. sub.run(current, exitstatus=1 if expect else 0) if expect: - checkExpect(sub.getOutput(), expect) + checkExpect(sub.getOutput(current), expect) return sub.run(current, args=["--unsub"]) diff --git a/cpp/test/IceStorm/repstress/test.py b/cpp/test/IceStorm/repstress/test.py index f61befa8961..8f0687cfa36 100644 --- a/cpp/test/IceStorm/repstress/test.py +++ b/cpp/test/IceStorm/repstress/test.py @@ -42,15 +42,15 @@ class IceStormRepStressTestCase(IceStormTestCase): current.write("running subscriber... ") subscriber = Subscriber(quiet=True) subscriber.start(current) - subscriber.expect("([^\n]+)\n") - subControl = subscriber.process.match.group(1) + subscriber.expect(current, "([^\n]+)\n") + subControl = subscriber.getMatch(current).group(1) current.writeln("ok") current.write("running publisher... ") publisher = Publisher(quiet=True) publisher.start(current) - publisher.expect("([^\n]+)\n") - pubControl = publisher.process.match.group(1) + publisher.expect(current, "([^\n]+)\n") + pubControl = publisher.getMatch(current).group(1) current.writeln("ok") time.sleep(2) @@ -89,8 +89,8 @@ class IceStormRepStressTestCase(IceStormTestCase): current.write("stopping publisher... ") Client(exe="control", args=[pubControl]).run(current) - publisher.expect("([^\n]+)\n") - publisherCount = publisher.process.match.group(1) + publisher.expect(current, "([^\n]+)\n") + publisherCount = publisher.getMatch(current).group(1) publisher.stop(current, True) current.writeln("ok") @@ -100,8 +100,8 @@ class IceStormRepStressTestCase(IceStormTestCase): current.write("stopping subscriber... ") Client(exe="control", args=[subControl]).run(current) - subscriber.expect("([^\n]+)\n") - subscriberCount = subscriber.process.match.group(1) + subscriber.expect(current, "([^\n]+)\n") + subscriberCount = subscriber.getMatch(current).group(1) subscriber.stop(current, True) current.writeln("ok") diff --git a/cpp/test/Slice/errorDetection/test.py b/cpp/test/Slice/errorDetection/test.py index 71953c3086c..32eec3e3f66 100644 --- a/cpp/test/Slice/errorDetection/test.py +++ b/cpp/test/Slice/errorDetection/test.py @@ -27,7 +27,7 @@ class SliceErrorDetectionTestCase(ClientTestCase): # Don't print out slice2cpp output and expect failures slice2cpp.run(current, args=args, exitstatus=1) - output = slice2cpp.getOutput() + output = slice2cpp.getOutput(current) regex1 = re.compile("\.ice$", re.IGNORECASE) lines1 = output.strip().split("\n") diff --git a/scripts/IceGridUtil.py b/scripts/IceGridUtil.py index bf5df85d50a..29e63e847de 100644 --- a/scripts/IceGridUtil.py +++ b/scripts/IceGridUtil.py @@ -259,7 +259,7 @@ class IceGridTestCase(TestCase): def runadmin(self, current, cmd, replica="Master", exitstatus=0, quiet=False): admin = IceGridAdmin(args=["-r", replica, "-e", cmd], replica=replica, quiet=quiet) admin.run(current, exitstatus=exitstatus) - return admin.getOutput() + return admin.getOutput(current) def runWithDriver(self, current): current.driver.runClientServerTestCase(current) diff --git a/scripts/IceStormUtil.py b/scripts/IceStormUtil.py index 79b31006e1f..ae38e14480c 100644 --- a/scripts/IceStormUtil.py +++ b/scripts/IceStormUtil.py @@ -204,7 +204,7 @@ class IceStormTestCase(TestCase): def runadmin(self, current, cmd, instanceName=None, instance=None, exitstatus=0, quiet=False): admin = IceStormAdmin(instanceName, instance, args=["-e", cmd], quiet=quiet) admin.run(current, exitstatus=exitstatus) - return admin.getOutput() + return admin.getOutput(current) def getTopicManager(self, current, instanceName=None): if not instanceName: diff --git a/scripts/LocalDriver.py b/scripts/LocalDriver.py index 97e173d0db1..b3d59be6d7e 100644 --- a/scripts/LocalDriver.py +++ b/scripts/LocalDriver.py @@ -424,7 +424,8 @@ class LocalDriver(Driver): current.config = conf testcase.run(current) except: - print(traceback.format_exc()) + if current.driver.debug: + current.result.writeln(traceback.format_exc()) raise finally: current.config = config diff --git a/scripts/Util.py b/scripts/Util.py index 7ca01fe669b..a316f24060a 100644 --- a/scripts/Util.py +++ b/scripts/Util.py @@ -929,8 +929,6 @@ class Process(Runnable): self.args = args or [] self.props = props or {} self.envs = envs or {} - self.process = None - self.output = None self.mapping = mapping def __str__(self): @@ -938,13 +936,13 @@ class Process(Runnable): return str(self.__class__) return self.exe + (" ({0})".format(self.desc) if self.desc else "") - def getOutput(self): - assert(self.process or self.output is not None) + def getOutput(self, current): + assert(self in current.processes) def d(s): return s if isPython2 else s.decode("utf-8") if isinstance(s, bytes) else s - output = d(self.process.getOutput() if self.process else self.output) + output = d(current.processes[self].getOutput()) try: # Apply outfilters to the output if len(self.outfilters) > 0: @@ -992,15 +990,17 @@ class Process(Runnable): self.start(current, args, props, watchDog=watchDog) if not self.quiet and not current.driver.isWorkerThread(): # Print out the process output to stdout if we're running the client form the main thread. - self.process.trace(self.outfilters) - while True: - try: - self.process.waitSuccess(exitstatus=exitstatus, timeout=30) - break - except Expect.TIMEOUT: - if watchDog and watchDog.timedOut(): - raise - self.stop(current, True, exitstatus) + current.processes[self].trace(self.outfilters) + try: + while True: + try: + current.processes[self].waitSuccess(exitstatus=exitstatus, timeout=30) + break + except Expect.TIMEOUT: + if watchDog and watchDog.timedOut(): + raise + finally: + self.stop(current, True, exitstatus) def getEffectiveArgs(self, current, args): allArgs = [] @@ -1038,8 +1038,8 @@ class Process(Runnable): allProps = self.getEffectiveProps(current, props) allEnvs = self.getEffectiveEnv(current) - self.output = None - self.process = current.driver.getProcessController(current).start(self, current, allArgs, allProps, allEnvs, watchDog) + processController = current.driver.getProcessController(current) + current.processes[self] = processController.start(self, current, allArgs, allProps, allEnvs, watchDog) try: self.waitForStart(current) except: @@ -1051,27 +1051,29 @@ class Process(Runnable): pass def stop(self, current, waitSuccess=False, exitstatus=0): - if self.process: + if self in current.processes: try: if waitSuccess: # Wait for the process to exit successfully by itself. - self.process.waitSuccess(exitstatus=exitstatus, timeout=60) + current.processes[self].waitSuccess(exitstatus=exitstatus, timeout=60) finally: - self.process.terminate() - self.output = self.process.getOutput() - self.process = None + current.processes[self].terminate() if not self.quiet: # Write the output to the test case (but not on stdout) - current.write(self.getOutput(), stdout=False) + current.write(self.getOutput(current), stdout=False) + + def expect(self, current, pattern, timeout=60): + assert(self in current.processes and isinstance(current.processes[self], Expect.Expect)) + return current.processes[self].expect(pattern, timeout) - def expect(self, pattern, timeout=60): - assert(self.process) - return self.process.expect(pattern, timeout) + def sendline(self, current, data): + assert(self in current.processes and isinstance(current.processes[self], Expect.Expect)) + return current.processes[self].sendline(data) - def sendline(self, data): - assert(self.process) - return self.process.sendline(data) + def getMatch(self, current): + assert(self in current.processes and isinstance(current.processes[self], Expect.Expect)) + return current.processes[self].match - def isStarted(self): - return self.process is not None + def isStarted(self, current): + return self in current.processes def isFromBinDir(self): return False @@ -1135,14 +1137,14 @@ class Server(IceProcess): def waitForStart(self, current): # Wait for the process to be ready - self.process.waitReady(self.ready, self.readyCount + (1 if current.config.mx else 0), self.startTimeout) + current.processes[self].waitReady(self.ready, self.readyCount + (1 if current.config.mx else 0), self.startTimeout) # Filter out remaining ready messages self.outfilters.append(re.compile("[^\n]+ ready")) # If we are not asked to be quiet and running from the main thread, print the server output if not self.quiet and not current.driver.isWorkerThread(): - self.process.trace(self.outfilters) + current.processes[self].trace(self.outfilters) def stop(self, current, waitSuccess=False, exitstatus=0): IceProcess.stop(self, current, waitSuccess and self.waitForShutdown, exitstatus) @@ -1360,7 +1362,7 @@ class TestCase(Runnable): self.stopServerSide(current, success) finally: for server in reversed(self.servers): - if server.isStarted(): + if server.isStarted(current): self._stopServer(current, server, False) self.teardownServerSide(current, success) current.pop() @@ -1664,7 +1666,7 @@ class ProcessController: class LocalProcessController(ProcessController): - class Process(Expect.Expect): + class LocalProcess(Expect.Expect): def waitReady(self, ready, readyCount, startTimeout): if ready: @@ -1713,13 +1715,13 @@ class LocalProcessController(ProcessController): env = os.environ.copy() env.update(envs) cwd = process.getMapping(current).getTestCwd(process, current) - process = LocalProcessController.Process(cmd, startReader=False, env=env, cwd=cwd, desc=process.desc) + process = LocalProcessController.LocalProcess(cmd, startReader=False, env=env, cwd=cwd, desc=process.desc) process.startReader(watchDog) return process class RemoteProcessController(ProcessController): - class Process: + class RemoteProcess: def __init__(self, exe, proxy): self.exe = exe self.proxy = proxy @@ -1865,7 +1867,7 @@ class RemoteProcessController(ProcessController): if self.adapter: prx = processController.ice_getConnection().createProxy(prx.ice_getIdentity()) import Test - return RemoteProcessController.Process(exe, Test.Common.ProcessPrx.uncheckedCast(prx)) + return RemoteProcessController.RemoteProcess(exe, Test.Common.ProcessPrx.uncheckedCast(prx)) def destroy(self, driver): if driver.controllerApp: @@ -2147,6 +2149,7 @@ class Driver: self.host = None self.testcase = None self.testcases = [] + self.processes = {} def getTestEndpoint(self, *args, **kargs): return self.driver.getTestEndpoint(*args, **kargs) diff --git a/scripts/tests/Slice/generation.py b/scripts/tests/Slice/generation.py index 528af0e9183..c6752e76eb1 100644 --- a/scripts/tests/Slice/generation.py +++ b/scripts/tests/Slice/generation.py @@ -10,7 +10,7 @@ class SliceGenerationTestCase(ClientTestCase): args=["--list-generated", "--output-dir", "classes", "File1.ice", "File2.ice"] + (["--compat"] if current.testcase.getPath().find("java-compat") >= 0 else [])) - lines1 = slice2java.getOutput().strip().split("\n") + lines1 = slice2java.getOutput(current).strip().split("\n") lines2 = open(os.path.join(self.getPath(), "list-generated.out"), "r").readlines() if len(lines1) != len(lines2): raise RuntimeError("failed!") |