Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
bcc430c2
Commit
bcc430c2
authored
Apr 01, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
686691ee
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
31 deletions
+27
-31
bigfile/tests/test_thread.py
bigfile/tests/test_thread.py
+27
-31
No files found.
bigfile/tests/test_thread.py
View file @
bcc430c2
...
...
@@ -23,38 +23,45 @@ from time import sleep
from
wendelin.bigfile.tests.test_basic
import
bord_py3
from
six.moves
import
_thread
from
golang
import
select
,
defaul
t
from
golang
import
chan
,
selec
t
from
golang
import
context
,
sync
# Notify channel for
# - one thread to .wait('condition')
, until
# - other thread
does
.tell('condition')
# - one thread to .wait('condition')
for
# - other thread
to
.tell('condition')
class
NotifyChannel
:
def
__init__
(
self
):
self
.
state
=
None
self
.
_ch
=
chan
()
def
tell
(
self
,
ctx
,
condition
):
#print >>sys.stderr, ' tell %s\tthread_id: %s\n' \
# % (condition, _thread.get_ident()),
# wait until other thread reads previous tell
while
self
.
state
is
not
None
:
if
ready
(
ctx
.
done
()):
_
,
_rx
=
select
(
ctx
.
done
().
recv
,
# 0
(
self
.
_ch
.
send
,
condition
),
# 1
)
if
_
==
0
:
raise
ctx
.
err
()
pass
self
.
state
=
condition
#print >>sys.stderr, ' told %s\tthread_id: %s\n' \
# % (condition, _thread.get_ident()),
def
wait
(
self
,
ctx
,
condition
):
#print >>sys.stderr, ' wait %s\tthread_id: %s\n' \
# % (condition, _thread.get_ident()),
while
self
.
state
!=
condition
:
if
ready
(
ctx
.
done
()):
_
,
_rx
=
select
(
ctx
.
done
().
recv
,
# 0
self
.
_ch
.
recv
,
# 1
)
if
_
==
0
:
raise
ctx
.
err
()
pass
got
=
_rx
if
got
!=
condition
:
raise
RuntimeError
(
'expected %s; got %s'
%
(
condition
,
got
))
#print >>sys.stderr, ' have %s\tthread_id: %s\n' \
# % (condition, _thread.get_ident()),
self
.
state
=
None
...
...
@@ -128,10 +135,12 @@ def test_thread_lock_vs_virtmem_lock():
m
[
0
]
# calls ZLockBigFile.loadblk()
tell
,
wait
=
c12
.
tell
,
c21
.
wait
wait
(
ctx
,
'T2-Z-released'
)
wait
(
ctx
,
'T2-Z-released
: 0
'
)
m
[
0
]
=
bord_py3
(
b'1'
)
# make page dirty
fh
.
dirty_writeout
(
WRITEOUT_STORE
)
# calls ZLockBigFile.storeblk()
wait
(
ctx
,
'T2-Z-released: 1'
)
def
T2
(
ctx
):
tell
,
wait
=
c21
.
tell
,
c12
.
wait
...
...
@@ -146,7 +155,7 @@ def test_thread_lock_vs_virtmem_lock():
fh2
.
invalidate_page
(
0
)
# NOTE invalidating page _not_ of fh
Z
.
release
()
tell
(
ctx
,
'T2-Z-released
'
)
tell
(
ctx
,
'T2-Z-released
: %d'
%
_
)
wg
=
sync
.
WorkGroup
(
context
.
background
())
wg
.
go
(
T1
)
...
...
@@ -289,16 +298,3 @@ def test_thread_load_vs_invalidate():
wg
.
go
(
T1
)
wg
.
go
(
T2
)
wg
.
wait
()
# ---- misc ----
def
ready
(
ch
):
_
,
_rx
=
select
(
default
,
# 0
ch
.
recv
,
# 1
)
if
_
==
0
:
return
False
return
True
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