1111
1212namespace Symfony \Component \Lock \Tests \Store ;
1313
14+ use Symfony \Component \Lock \Key ;
1415use Symfony \Component \Lock \Store \SemaphoreStore ;
1516
1617/**
@@ -33,4 +34,31 @@ protected function getStore()
3334
3435 return new SemaphoreStore ();
3536 }
37+
38+ public function testResourceRemoval ()
39+ {
40+ $ initialCount = $ this ->getOpenedSemaphores ();
41+ $ store = new SemaphoreStore ();
42+ $ key = new Key (uniqid (__METHOD__ , true ));
43+ $ store ->waitAndSave ($ key );
44+
45+ $ this ->assertGreaterThan ($ initialCount , $ this ->getOpenedSemaphores (), 'Semaphores should have been created ' );
46+
47+ $ store ->delete ($ key );
48+ $ this ->assertEquals ($ initialCount , $ this ->getOpenedSemaphores (), 'All semaphores should be removed ' );
49+ }
50+
51+ private function getOpenedSemaphores ()
52+ {
53+ $ lines = explode (PHP_EOL , trim (`ipcs -su `));
54+ if ('------ Semaphore Status -------- ' !== $ lines [0 ]) {
55+ throw new \Exception ('Failed to extract list of opend semaphores. Expect a Semaphore status, got ' .implode (PHP_EOL , $ lines ));
56+ }
57+ list ($ key , $ value ) = explode (' = ' , $ lines [1 ]);
58+ if ('used arrays ' !== $ key ) {
59+ throw new \Exception ('Failed to extract list of opend semaphores. Expect a used arrays key, got ' .implode (PHP_EOL , $ lines ));
60+ }
61+
62+ return (int ) $ value ;
63+ }
3664}
0 commit comments