-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from doronz88/feature/thread_safe
client: server: support concurrency
- Loading branch information
Showing
6 changed files
with
101 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import time | ||
from threading import Thread | ||
|
||
|
||
def test_same_socket_different_threads(client): | ||
# get an expected result once on main thread | ||
expected_result = client.fs.listdir('/') | ||
|
||
# global to tell threads when to exit | ||
should_exit = False | ||
|
||
def listdir_thread(client): | ||
while not should_exit: | ||
assert client.fs.listdir('/') == expected_result | ||
return 0 | ||
|
||
# launch the two threads | ||
t1 = Thread(target=listdir_thread, args=(client,)) | ||
t2 = Thread(target=listdir_thread, args=(client,)) | ||
|
||
t1.start() | ||
t2.start() | ||
|
||
# wait 10 seconds | ||
time.sleep(10) | ||
|
||
# tell threads they | ||
should_exit = True | ||
|
||
t1.join() | ||
t2.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters