1212import requests
1313import sh
1414
15+ POLL_FREQUENCY = 0.5 # How long to sleep inbetween calls to the method
16+
17+
18+ class TimeoutException (Exception ):
19+ """
20+ Thrown when a command does not complete in enough time.
21+ """
22+ pass
23+
24+
25+ def wait_until_running (timeout = 120 ):
26+ end_time = time .time () + timeout
27+ while True :
28+ try :
29+ response = requests .get ("http://localhost/api/version" )
30+ if response .status_code != 502 :
31+ return
32+ except requests .exceptions .ConnectionError :
33+ pass
34+ time .sleep (POLL_FREQUENCY )
35+ if time .time () > end_time :
36+ break
37+ raise TimeoutException ()
38+
1539
1640class WireCloudTests (object ):
1741
@@ -48,11 +72,12 @@ class StandaloneTests(unittest.TestCase, WireCloudTests):
4872
4973 @classmethod
5074 def setUpClass (cls ):
75+ print ("\n ################################################################################\n " )
5176 print ("#" )
5277 print ("# Initializing standalone test case" )
5378 print ("#\n " )
5479 sh .docker_compose ("-f" , "docker-compose-standalone.yml" , "up" , d = True , remove_orphans = True , _fg = True )
55- time . sleep ( 30 )
80+ wait_until_running ( )
5681 print ()
5782
5883 @classmethod
@@ -71,11 +96,12 @@ class SimpleTests(unittest.TestCase, WireCloudTests):
7196
7297 @classmethod
7398 def setUpClass (cls ):
99+ print ("\n ################################################################################\n " )
74100 print ("#" )
75101 print ("# Initializing simple test case" )
76102 print ("#\n " )
77103 sh .docker_compose ("-f" , "docker-compose-simple.yml" , "up" , d = True , remove_orphans = True , _fg = True )
78- time . sleep ( 30 )
104+ wait_until_running ( )
79105 print ()
80106
81107 @classmethod
@@ -94,11 +120,39 @@ class ComposedTests(unittest.TestCase, WireCloudTests):
94120
95121 @classmethod
96122 def setUpClass (cls ):
123+ print ("\n ################################################################################\n " )
97124 print ("#" )
98125 print ("# Initializing composed test case" )
99126 print ("#\n " )
100127 sh .docker_compose .up (d = True , remove_orphans = True , _fg = True )
101- time .sleep (30 )
128+ wait_until_running ()
129+ print ()
130+
131+ @classmethod
132+ def tearDownClass (cls ):
133+ print ()
134+ print ("#" )
135+ print ("# Removing containers and volumes" )
136+ print ("#\n " )
137+ sh .docker_compose .down (remove_orphans = True , v = True , _fg = True )
138+ shutil .rmtree ('wirecloud-data' )
139+ shutil .rmtree ('wirecloud-static' )
140+ shutil .rmtree ('elasticsearch-data' )
141+ shutil .rmtree ('postgres-data' )
142+ print ()
143+
144+
145+ class ReadOnlyConfigTests (unittest .TestCase , WireCloudTests ):
146+
147+ @classmethod
148+ def setUpClass (cls ):
149+ print ("\n ################################################################################\n " )
150+ print ("#" )
151+ print ("# Initializing read-only config test case" )
152+ print ("#\n " )
153+
154+ sh .docker_compose ("-f" , "docker-compose-config-file.yml" , "up" , d = True , remove_orphans = True , _fg = True )
155+ wait_until_running ()
102156 print ()
103157
104158 @classmethod
@@ -119,6 +173,7 @@ class IDMTests(unittest.TestCase, WireCloudTests):
119173
120174 @classmethod
121175 def setUpClass (cls ):
176+ print ("\n ################################################################################\n " )
122177 print ("#" )
123178 print ("# Initializing idm test case" )
124179 print ("#\n " )
@@ -129,7 +184,7 @@ def setUpClass(cls):
129184 env ["SOCIAL_AUTH_FIWARE_KEY" ] = "wirecloud_test_client_id"
130185 env ["SOCIAL_AUTH_FIWARE_SECRET" ] = "notused"
131186 sh .docker_compose ("-f" , "docker-compose-idm.yml" , "up" , d = True , remove_orphans = True , _env = env , _fg = True )
132- time . sleep ( 45 )
187+ wait_until_running ( )
133188 print ()
134189
135190 @classmethod
0 commit comments