8000 Debug php5-memcache · symfony/symfony@bf0ed7b · GitHub
[go: up one dir, main page]

Skip to content

Commit bf0ed7b

Browse files
committed
Debug php5-memcache
1 parent 01d1563 commit bf0ed7b

File tree

3 files changed

+94
-16
lines changed

3 files changed

+94
-16
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/Store/MemcachedStore.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ 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';
63+
var_dump($this->memcached->getResultCode());
6264
return;
6365
}
66+
echo 'putOffExpiration';
6467

6568
// the lock is already acquire. It could be us. Let's try to put off.
6669
$this->putOffExpiration($key, $this->initialTtl);

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

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

1212
namespace Symfony\Component\Lock\Tests\Store;
1313

14+
use Psr\Log\AbstractLogger;
15+
use Symfony\Component\Lock\Exception\LockConflictedException;
16+
use Symfony\Component\Lock\Key;
1417
use Symfony\Component\Lock\Store\MemcachedStore;
1518

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

5053
return new MemcachedStore($memcached);
5154
}
55+
56+
/**
57+
* @dataProvider lotOfData
58+
*/
59+
public function testSaveWithDifferentResources()
60+
{
61+
$store = $this->getStore();
62+
63+
$key1 = new Key(uniqid(__METHOD__, true));
64+
$key2 = new Key(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+
public function testSaveWithDifferentKeysOnSameResources()
95+
{
96+
$store = $this->getStore();
97+
98+
$resource = uniqid(__METHOD__, true);
99+
$key1 = new Key($resource);
100+
$key2 = new Key($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+
$store->save($key2);
109+
var_dump('2');
110+
var_dump($key1);
111+
var_dump($key2);
112+
var_dump(microtime(true) - $start);
113+
$memcached = new \Memcached();
114+
$memcached->addServer(getenv('MEMCACHED_HOST'), 11211);
115+
var_dump($memcached->get($resource));
116+
die;
117+
throw new \Exception('The store shouldn\'t save the second key');
118+
} catch (LockConflictedException $e) {
119+
}
120+
121+
// The failure of previous attempt should not impact the state of current locks
122+
$this->assertTrue($store->exists($key1));
123+
$this->assertFalse($store->exists($key2));
124+
125+
$store->delete($key1);
126+
$this->assertFalse($store->exists($key1));
127+
$this->assertFalse($store->exists($key2));
128+
129+
$store->save($key2);
130+
$this->assertFalse($store->exists($key1));
131+
$this->assertTrue($store->exists($key2));
132+
133+
$store->delete($key2);
134+
$this->assertFalse($store->exists($key1));
135+
$this->assertFalse($store->exists($key2));
136+
}
137+
138+
public function lotOfData()
139+
{
140+
return array_fill(0, 1000, []);
141+
}
52142
}

0 commit comments

Comments
 (0)
0