Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
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
cpython
Commits
369a7822
Kaydet (Commit)
369a7822
authored
Ock 08, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16843: Make concurrent tests for sched module deterministic.
üst
ae3b32ad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
21 deletions
+85
-21
test_sched.py
Lib/test/test_sched.py
+85
-21
No files found.
Lib/test/test_sched.py
Dosyayı görüntüle @
369a7822
#!/usr/bin/env python
#!/usr/bin/env python
import
queue
import
sched
import
sched
import
time
import
time
import
unittest
import
unittest
...
@@ -9,6 +10,37 @@ try:
...
@@ -9,6 +10,37 @@ try:
except
ImportError
:
except
ImportError
:
threading
=
None
threading
=
None
TIMEOUT
=
10
class
Timer
:
def
__init__
(
self
):
self
.
_cond
=
threading
.
Condition
()
self
.
_time
=
0
self
.
_stop
=
0
def
time
(
self
):
with
self
.
_cond
:
return
self
.
_time
# increase the time but not beyond the established limit
def
sleep
(
self
,
t
):
assert
t
>=
0
with
self
.
_cond
:
t
+=
self
.
_time
while
self
.
_stop
<
t
:
self
.
_time
=
self
.
_stop
self
.
_cond
.
wait
()
self
.
_time
=
t
# advance time limit for user code
def
advance
(
self
,
t
):
assert
t
>=
0
with
self
.
_cond
:
self
.
_stop
+=
t
self
.
_cond
.
notify_all
()
class
TestCase
(
unittest
.
TestCase
):
class
TestCase
(
unittest
.
TestCase
):
def
test_enter
(
self
):
def
test_enter
(
self
):
...
@@ -31,17 +63,34 @@ class TestCase(unittest.TestCase):
...
@@ -31,17 +63,34 @@ class TestCase(unittest.TestCase):
@unittest.skipUnless
(
threading
,
'Threading required for this test.'
)
@unittest.skipUnless
(
threading
,
'Threading required for this test.'
)
def
test_enter_concurrent
(
self
):
def
test_enter_concurrent
(
self
):
l
=
[]
q
=
queue
.
Queue
()
fun
=
lambda
x
:
l
.
append
(
x
)
fun
=
q
.
put
scheduler
=
sched
.
scheduler
(
time
.
time
,
time
.
sleep
)
timer
=
Timer
()
scheduler
.
enter
(
0.03
,
1
,
fun
,
(
0.03
,))
scheduler
=
sched
.
scheduler
(
timer
.
time
,
timer
.
sleep
)
scheduler
.
enter
(
1
,
1
,
fun
,
(
1
,))
scheduler
.
enter
(
3
,
1
,
fun
,
(
3
,))
t
=
threading
.
Thread
(
target
=
scheduler
.
run
)
t
=
threading
.
Thread
(
target
=
scheduler
.
run
)
t
.
start
()
t
.
start
()
for
x
in
[
0.05
,
0.04
,
0.02
,
0.01
]:
timer
.
advance
(
1
)
z
=
scheduler
.
enter
(
x
,
1
,
fun
,
(
x
,))
self
.
assertEqual
(
q
.
get
(
timeout
=
TIMEOUT
),
1
)
scheduler
.
run
()
self
.
assertTrue
(
q
.
empty
())
t
.
join
()
for
x
in
[
4
,
5
,
2
]:
self
.
assertEqual
(
l
,
[
0.01
,
0.02
,
0.03
,
0.04
,
0.05
])
z
=
scheduler
.
enter
(
x
-
1
,
1
,
fun
,
(
x
,))
timer
.
advance
(
2
)
self
.
assertEqual
(
q
.
get
(
timeout
=
TIMEOUT
),
2
)
self
.
assertEqual
(
q
.
get
(
timeout
=
TIMEOUT
),
3
)
self
.
assertTrue
(
q
.
empty
())
timer
.
advance
(
1
)
self
.
assertEqual
(
q
.
get
(
timeout
=
TIMEOUT
),
4
)
self
.
assertTrue
(
q
.
empty
())
timer
.
advance
(
1
)
self
.
assertEqual
(
q
.
get
(
timeout
=
TIMEOUT
),
5
)
self
.
assertTrue
(
q
.
empty
())
timer
.
advance
(
1000
)
t
.
join
(
timeout
=
TIMEOUT
)
self
.
assertFalse
(
t
.
is_alive
())
self
.
assertTrue
(
q
.
empty
())
self
.
assertEqual
(
timer
.
time
(),
5
)
def
test_priority
(
self
):
def
test_priority
(
self
):
l
=
[]
l
=
[]
...
@@ -69,21 +118,36 @@ class TestCase(unittest.TestCase):
...
@@ -69,21 +118,36 @@ class TestCase(unittest.TestCase):
@unittest.skipUnless
(
threading
,
'Threading required for this test.'
)
@unittest.skipUnless
(
threading
,
'Threading required for this test.'
)
def
test_cancel_concurrent
(
self
):
def
test_cancel_concurrent
(
self
):
l
=
[]
q
=
queue
.
Queue
()
fun
=
lambda
x
:
l
.
append
(
x
)
fun
=
q
.
put
scheduler
=
sched
.
scheduler
(
time
.
time
,
time
.
sleep
)
timer
=
Timer
()
now
=
time
.
time
()
scheduler
=
sched
.
scheduler
(
timer
.
time
,
timer
.
sleep
)
event1
=
scheduler
.
enterabs
(
now
+
0.01
,
1
,
fun
,
(
0.01
,))
now
=
timer
.
time
()
event2
=
scheduler
.
enterabs
(
now
+
0.02
,
1
,
fun
,
(
0.02
,))
event1
=
scheduler
.
enterabs
(
now
+
1
,
1
,
fun
,
(
1
,))
event3
=
scheduler
.
enterabs
(
now
+
0.03
,
1
,
fun
,
(
0.03
,))
event2
=
scheduler
.
enterabs
(
now
+
2
,
1
,
fun
,
(
2
,))
event4
=
scheduler
.
enterabs
(
now
+
0.04
,
1
,
fun
,
(
0.04
,))
event4
=
scheduler
.
enterabs
(
now
+
4
,
1
,
fun
,
(
4
,))
event5
=
scheduler
.
enterabs
(
now
+
0.05
,
1
,
fun
,
(
0.05
,))
event5
=
scheduler
.
enterabs
(
now
+
5
,
1
,
fun
,
(
5
,))
event3
=
scheduler
.
enterabs
(
now
+
3
,
1
,
fun
,
(
3
,))
t
=
threading
.
Thread
(
target
=
scheduler
.
run
)
t
=
threading
.
Thread
(
target
=
scheduler
.
run
)
t
.
start
()
t
.
start
()
scheduler
.
cancel
(
event1
)
timer
.
advance
(
1
)
self
.
assertEqual
(
q
.
get
(
timeout
=
TIMEOUT
),
1
)
self
.
assertTrue
(
q
.
empty
())
scheduler
.
cancel
(
event2
)
scheduler
.
cancel
(
event5
)
scheduler
.
cancel
(
event5
)
t
.
join
()
timer
.
advance
(
1
)
self
.
assertEqual
(
l
,
[
0.02
,
0.03
,
0.04
])
self
.
assertTrue
(
q
.
empty
())
timer
.
advance
(
1
)
self
.
assertEqual
(
q
.
get
(
timeout
=
TIMEOUT
),
3
)
self
.
assertTrue
(
q
.
empty
())
timer
.
advance
(
1
)
self
.
assertEqual
(
q
.
get
(
timeout
=
TIMEOUT
),
4
)
self
.
assertTrue
(
q
.
empty
())
timer
.
advance
(
1000
)
t
.
join
(
timeout
=
TIMEOUT
)
self
.
assertFalse
(
t
.
is_alive
())
self
.
assertTrue
(
q
.
empty
())
self
.
assertEqual
(
timer
.
time
(),
4
)
def
test_empty
(
self
):
def
test_empty
(
self
):
l
=
[]
l
=
[]
...
...
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