Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0e4ca67

Browse files
committed
Debug php5-memcache
1 parent01d1563 commit0e4ca67

File tree

4 files changed

+98
-18
lines changed

4 files changed

+98
-18
lines changed

‎.travis.yml‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,8 @@ env:
2020

2121
matrix:
2222
include:
23-
# Use the newer stack for HHVM as HHVM does not support Precise anymore since a long time and so Precise has an outdated version
24-
-php:hhvm-3.18
25-
sudo:required
26-
dist:trusty
27-
group:edge
2823
-php:5.5
2924
-php:5.6
30-
-php:7.1
31-
env:deps=high
32-
-php:7.0
33-
env:deps=low
3425
fast_finish:true
3526

3627
cache:
@@ -91,13 +82,7 @@ before_install:
9182
echo extension = mongodb.so >> $INI
9283
fi
9384
94-
# Matrix lines for intermediate PHP versions are skipped for pull requests
95-
if [[ ! $deps && ! $PHP = ${MIN_PHP%.*} && ! $PHP = hhvm* && $TRAVIS_PULL_REQUEST != false ]]; then
96-
deps=skip
97-
skip=1
98-
else
99-
COMPONENTS=$(find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist -printf '%h\n')
100-
fi
85+
COMPONENTS=$(find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist -printf '%h\n')
10186
10287
-|
10388
# Install sigchild-enabled PHP to test the Process component on the lowest PHP matrix line

‎src/Symfony/Component/Lock/Key.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class Key
2626
*/
2727
publicfunction__construct($resource)
2828
{
29-
$this->resource =(string)$resource;
29+
$this->resource =md5((string)$resource);
3030
}
3131

3232
publicfunction__toString()

‎src/Symfony/Component/Lock/Store/MemcachedStore.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ public function save(Key $key)
5959
$token =$this->getToken($key);
6060

6161
if ($this->memcached->add((string)$key,$token, (int)ceil($this->initialTtl))) {
62+
echo'memcached->add';
6263
return;
6364
}
65+
echo'putOffExpiration';
6466

6567
// the lock is already acquire. It could be us. Let's try to put off.
6668
$this->putOffExpiration($key,$this->initialTtl);
@@ -149,7 +151,7 @@ public function exists(Key $key)
149151
privatefunctiongetToken(Key$key)
150152
{
151153
if (!$key->hasState(__CLASS__)) {
152-
$token =base64_encode(random_bytes(32));
154+
$token =md5(base64_encode(random_bytes(32)));
153155
$key->setState(__CLASS__,$token);
154156
}
155157

‎src/Symfony/Component/Lock/Tests/Store/MemcachedStoreTest.php‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespaceSymfony\Component\Lock\Tests\Store;
1313

14+
usePsr\Log\AbstractLogger;
15+
useSymfony\Component\Lock\Exception\LockConflictedException;
16+
useSymfony\Component\Lock\Key;
1417
useSymfony\Component\Lock\Store\MemcachedStore;
1518

1619
/**
@@ -49,4 +52,94 @@ public function getStore()
4952

5053
returnnewMemcachedStore($memcached);
5154
}
55+
56+
/**
57+
* @dataProvider lotOfData
58+
*/
59+
publicfunctiontestSaveWithDifferentResources()
60+
{
61+
$store =$this->getStore();
62+
63+
$key1 =newKey(uniqid(__METHOD__,true));
64+
$key2 =newKey(uniqid(__METHOD__,true));
65+
66+
$store->save($key1);
67+
try {
68+
$this->assertTrue($store->exists($key1));
69+
}catch (\Exception$e) {
70+
var_dump('1');
71+
var_dump($key1);
72+
$memcached =new \Memcached();
73+
$memcached->addServer(getenv('MEMCACHED_HOST'),11211);
74+
var_dump($memcached->get((string)$key1));
75+
die;
76+
throw$e;
77+
}
78+
$this->assertFalse($store->exists($key2));
79+
80+
$store->save($key2);
81+
82+
$this->assertTrue($store->exists($key1));
83+
$this->assertTrue($store->exists($key2));
84+
85+
$store->delete($key1);
86+
$this->assertFalse($store->exists($key1));
87+
$store->delete($key2);
88+
$this->assertFalse($store->exists($key2));
89+
}
90+
91+
/**
92+
* @dataProvider lotOfData
93+
*/
94+
publicfunctiontestSaveWithDifferentKeysOnSameResources()
95+
{
96+
$store =$this->getStore();
97+
98+
$resource =uniqid(__METHOD__,true);
99+
$key1 =newKey($resource);
100+
$key2 =newKey($resource);
101+
102+
$start =microtime(true);
103+
$store->save($key1);
104+
$this->assertTrue($store->exists($key1));
105+
$this->assertFalse($store->exists($key2));
106+
107+
try {
108+
$memcached =new \Memcached();
109+
$memcached->addServer(getenv('MEMCACHED_HOST'),11211);
110+
var_dump($memcached->get($resource));
111+
112+
$store->save($key2);
113+
114+
var_dump('2');
115+
var_dump($key1);
116+
var_dump($key2);
117+
var_dump(microtime(true) -$start);
118+
var_dump($memcached->get($resource));
119+
die;
120+
thrownew \Exception('The store shouldn\'t save the second key');
121+
}catch (LockConflictedException$e) {
122+
}
123+
124+
// The failure of previous attempt should not impact the state of current locks
125+
$this->assertTrue($store->exists($key1));
126+
$this->assertFalse($store->exists($key2));
127+
128+
$store->delete($key1);
129+
$this->assertFalse($store->exists($key1));
130+
$this->assertFalse($store->exists($key2));
131+
132+
$store->save($key2);
133+
$this->assertFalse($store->exists($key1));
134+
$this->assertTrue($store->exists($key2));
135+
136+
$store->delete($key2);
137+
$this->assertFalse($store->exists($key1));
138+
$this->assertFalse($store->exists($key2));
139+
}
140+
141+
publicfunctionlotOfData()
142+
{
143+
returnarray_fill(0,1000, []);
144+
}
52145
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp