forked from douban/libmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
550ef71
commit f099e68
Showing
4 changed files
with
68 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# coding: utf-8 | ||
import unittest | ||
from threading import Thread | ||
from libmc import ClientPool | ||
|
||
|
||
class ThreadedSingleServerCase(unittest.TestCase): | ||
def setUp(self): | ||
self.pool = ClientPool(["127.0.0.1:21211"]) | ||
|
||
def misc(self): | ||
for i in range(5): | ||
with self.pool.client() as mc: | ||
tid = str(mc._get_current_thread_ident() + (i,)) | ||
f, t = 'foo ' + tid, 'tuiche ' + tid | ||
mc.get_multi([f, t]) | ||
mc.delete(f) | ||
mc.delete(t) | ||
assert mc.get(f) is None | ||
assert mc.get(t) is None | ||
|
||
mc.set(f, 'biu') | ||
mc.set(t, 'bb') | ||
assert mc.get(f) == 'biu' | ||
assert mc.get(t) == 'bb' | ||
assert (mc.get_multi([f, t]) == | ||
{f: 'biu', t: 'bb'}) | ||
mc.set_multi({f: 1024, t: '8964'}) | ||
assert (mc.get_multi([f, t]) == | ||
{f: 1024, t: '8964'}) | ||
|
||
def test_misc(self): | ||
ts = [Thread(target=self.misc) for i in range(8)] | ||
for t in ts: | ||
t.start() | ||
|
||
for t in ts: | ||
t.join() |