1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* test for locking feature |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\RestBundle\Tests\Controller; |
7
|
|
|
|
8
|
|
|
use Graviton\TestBundle\Test\RestTestCase; |
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
13
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
14
|
|
|
* @link http://swisscom.ch |
15
|
|
|
*/ |
16
|
|
|
class AsyncLockingTest extends RestTestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* try to send 30 async requests to /event/status and see if the result is consistent |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
public function testAsyncLock() |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* create test entry |
28
|
|
|
*/ |
29
|
|
|
$client = static::createRestClient(); |
30
|
|
|
$statusEntry = new \stdClass(); |
31
|
|
|
$statusEntry->id = 'locktest'; |
32
|
|
|
$statusEntry->status = []; |
33
|
|
|
$defaultStatus = new \stdClass(); |
34
|
|
|
$defaultStatus->workerId = 'hans'; |
35
|
|
|
$defaultStatus->status = 'opened'; |
36
|
|
|
$statusEntry->status[] = $defaultStatus; |
37
|
|
|
|
38
|
|
|
$client->put('/event/status/locktest', $statusEntry); |
39
|
|
|
$this->assertSame(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode()); |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* the patch we will send |
43
|
|
|
*/ |
44
|
|
|
$patchJson = json_encode( |
45
|
|
|
[ |
46
|
|
|
[ |
47
|
|
|
'op' => 'replace', |
48
|
|
|
'path' => '/status/0/status', |
49
|
|
|
'value' => 'ignored' |
50
|
|
|
], |
51
|
|
|
[ |
52
|
|
|
'op' => 'add', |
53
|
|
|
'path' => '/status/0/action', |
54
|
|
|
'value' => [ |
55
|
|
|
'$ref' => 'http://localhost/event/action/default' |
56
|
|
|
] |
57
|
|
|
], |
58
|
|
|
[ |
59
|
|
|
'op' => 'add', |
60
|
|
|
'path' => '/information/-', |
61
|
|
|
'value' => [ |
62
|
|
|
'workerId' => 'hans', |
63
|
|
|
'type' => 'info', |
64
|
|
|
'content' => 'addedInfo' |
65
|
|
|
] |
66
|
|
|
] |
67
|
|
|
] |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$promiseStack = []; |
71
|
|
|
$deferred = new \React\Promise\Deferred(); |
72
|
|
|
|
73
|
|
|
$i = 0; |
74
|
|
|
while ($i < 30) { |
75
|
|
|
$promise = $deferred->promise(); |
76
|
|
|
|
77
|
|
|
$promise->then( |
78
|
|
|
function () use ($patchJson) { |
79
|
|
|
$client = static::createRestClient(); |
80
|
|
|
$client->request('PATCH', '/event/status/locktest', [], [], [], $patchJson); |
81
|
|
|
$this->assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode()); |
82
|
|
|
} |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$promiseStack[] = $promise; |
86
|
|
|
$i++; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
\React\Promise\all($promiseStack)->then( |
90
|
|
View Code Duplication |
function () { |
91
|
|
|
// after all is done; check entry |
92
|
|
|
$client = static::createRestClient(); |
93
|
|
|
$client->request('GET', '/event/status/locktest'); |
94
|
|
|
$result = $client->getResults(); |
95
|
|
|
|
96
|
|
|
$this->assertSame(30, count($result->information)); |
97
|
|
|
$this->assertSame(1, count($result->status)); |
98
|
|
|
} |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
// start the whole thing |
102
|
|
|
$deferred->resolve(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|