Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
6bb7844a
Kaydet (Commit)
6bb7844a
authored
Kas 11, 2016
tarafından
Aanand Prasad
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Rework healthcheck integration test
Signed-off-by:
Aanand Prasad
<
aanand.prasad@gmail.com
>
üst
b4f2b5fa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
27 deletions
+57
-27
helpers.py
tests/helpers.py
+9
-0
healthcheck_test.py
tests/integration/healthcheck_test.py
+48
-27
No files found.
tests/helpers.py
Dosyayı görüntüle @
6bb7844a
...
...
@@ -2,6 +2,7 @@ import os
import
os.path
import
tarfile
import
tempfile
import
time
import
docker
import
pytest
...
...
@@ -47,3 +48,11 @@ def requires_api_version(version):
),
reason
=
"API version is too low (< {0})"
.
format
(
version
)
)
def
wait_on_condition
(
condition
,
delay
=
0.1
,
timeout
=
40
):
start_time
=
time
.
time
()
while
not
condition
():
if
time
.
time
()
-
start_time
>
timeout
:
raise
AssertionError
(
"Timeout:
%
s"
%
condition
)
time
.
sleep
(
delay
)
tests/integration/healthcheck_test.py
Dosyayı görüntüle @
6bb7844a
import
time
import
docker
from
..base
import
requires_api_version
from
.base
import
BaseIntegrationTest
from
.base
import
BUSYBOX
from
..
import
helpers
SECOND
=
1000000000
class
HealthcheckTest
(
helpers
.
BaseTestCase
):
@requires_api_version
(
'1.21'
)
def
test_healthcheck
(
self
):
class
HealthcheckTest
(
BaseIntegrationTest
):
@helpers.requires_api_version
(
'1.24'
)
def
test_healthcheck_passes
(
self
):
healthcheck
=
docker
.
types
.
Healthcheck
(
test
=
[
"CMD-SHELL"
,
"foo.txt || (/bin/usleep 10000 && touch foo.txt)"
],
interval
=
500000
,
timeout
=
1000000000
,
retries
=
1
test
=
[
"CMD-SHELL"
,
"true"
],
interval
=
1
*
SECOND
,
timeout
=
1
*
SECOND
,
retries
=
1
,
)
container
=
self
.
client
.
create_container
(
helpers
.
BUSYBOX
,
'cat'
,
detach
=
True
,
stdin_open
=
True
,
healthcheck
=
healthcheck
)
id
=
container
[
'Id'
]
self
.
client
.
start
(
id
)
self
.
tmp_containers
.
append
(
id
)
res1
=
self
.
client
.
inspect_container
(
id
)
self
.
assertIn
(
'State'
,
res1
)
self
.
assertIn
(
'Health'
,
res1
[
'State'
])
self
.
assertIn
(
'Status'
,
res1
[
'State'
][
'Health'
])
self
.
assertEqual
(
res1
[
'State'
][
'Health'
][
'Status'
],
"starting"
)
time
.
sleep
(
0.5
)
res2
=
self
.
client
.
inspect_container
(
id
)
self
.
assertIn
(
'State'
,
res2
)
self
.
assertIn
(
'Health'
,
res2
[
'State'
])
self
.
assertIn
(
'Status'
,
res2
[
'State'
][
'Health'
])
self
.
assertEqual
(
res2
[
'State'
][
'Health'
][
'Status'
],
"healthy"
)
container
=
self
.
client
.
create_container
(
BUSYBOX
,
'top'
,
healthcheck
=
healthcheck
)
self
.
tmp_containers
.
append
(
container
)
res
=
self
.
client
.
inspect_container
(
container
)
assert
res
[
'Config'
][
'Healthcheck'
]
==
{
"Test"
:
[
"CMD-SHELL"
,
"true"
],
"Interval"
:
1
*
SECOND
,
"Timeout"
:
1
*
SECOND
,
"Retries"
:
1
,
}
def
condition
():
res
=
self
.
client
.
inspect_container
(
container
)
return
res
[
'State'
][
'Health'
][
'Status'
]
==
"healthy"
self
.
client
.
start
(
container
)
helpers
.
wait_on_condition
(
condition
)
@helpers.requires_api_version
(
'1.24'
)
def
test_healthcheck_fails
(
self
):
healthcheck
=
docker
.
types
.
Healthcheck
(
test
=
[
"CMD-SHELL"
,
"false"
],
interval
=
1
*
SECOND
,
timeout
=
1
*
SECOND
,
retries
=
1
,
)
container
=
self
.
client
.
create_container
(
BUSYBOX
,
'top'
,
healthcheck
=
healthcheck
)
self
.
tmp_containers
.
append
(
container
)
def
condition
():
res
=
self
.
client
.
inspect_container
(
container
)
return
res
[
'State'
][
'Health'
][
'Status'
]
==
"unhealthy"
self
.
client
.
start
(
container
)
helpers
.
wait_on_condition
(
condition
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment