1 | #Licensed to the Apache Software Foundation (ASF) under one |
---|
2 | #or more contributor license agreements. See the NOTICE file |
---|
3 | #distributed with this work for additional information |
---|
4 | #regarding copyright ownership. The ASF licenses this file |
---|
5 | #to you under the Apache License, Version 2.0 (the |
---|
6 | #"License"); you may not use this file except in compliance |
---|
7 | #with the License. You may obtain a copy of the License at |
---|
8 | |
---|
9 | # http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | |
---|
11 | #Unless required by applicable law or agreed to in writing, software |
---|
12 | #distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | #See the License for the specific language governing permissions and |
---|
15 | #limitations under the License. |
---|
16 | import unittest, os, sys, re, threading, time |
---|
17 | |
---|
18 | myDirectory = os.path.realpath(sys.argv[0]) |
---|
19 | rootDirectory = re.sub("/testing/.*", "", myDirectory) |
---|
20 | |
---|
21 | sys.path.append(rootDirectory) |
---|
22 | |
---|
23 | from testing.lib import BaseTestSuite |
---|
24 | from hodlib.Common.util import * |
---|
25 | from hodlib.Common.threads import simpleCommand |
---|
26 | |
---|
27 | excludes = [] |
---|
28 | |
---|
29 | class test_Util(unittest.TestCase): |
---|
30 | |
---|
31 | def testProcessStatus(self): |
---|
32 | sc = simpleCommand('testsleep', 'sleep 60') |
---|
33 | sc.start() |
---|
34 | pid = sc.getPid() |
---|
35 | while pid is None: |
---|
36 | pid = sc.getPid() |
---|
37 | self.assertTrue(isProcessRunning(pid)) |
---|
38 | sc.kill() |
---|
39 | sc.wait() |
---|
40 | sc.join() |
---|
41 | self.assertFalse(isProcessRunning(pid)) |
---|
42 | |
---|
43 | |
---|
44 | class UtilTestSuite(BaseTestSuite): |
---|
45 | def __init__(self): |
---|
46 | # suite setup |
---|
47 | BaseTestSuite.__init__(self, __name__, excludes) |
---|
48 | pass |
---|
49 | |
---|
50 | def cleanUp(self): |
---|
51 | # suite tearDown |
---|
52 | pass |
---|
53 | |
---|
54 | def RunUtilTests(): |
---|
55 | # modulename_suite |
---|
56 | suite = UtilTestSuite() |
---|
57 | testResult = suite.runTests() |
---|
58 | suite.cleanUp() |
---|
59 | return testResult |
---|
60 | |
---|
61 | if __name__ == "__main__": |
---|
62 | RunUtilTests() |
---|