PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.20
ووسلام – همگام سازی ووکامرس و باسلام v1.10.20
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
← All changes | tests/JobsRunnerTest.php +24 -31 1.10.151.10.20 View file →
@@ -41,18 +41,18 @@
41 41
42 42 unset($GLOBALS['sync_basalam_jobs_runner_test_state']);
43 43 }
44 44
45 - public function testRegistersDispatcherOnInitAndNeverOnShutdown(): void
45 + public function testRegistersDispatcherOnShutdownAndNeverOnInit(): void
46 46 {
47 47 $runner = $this->newRunner();
48 48 $actions = $this->state()['actions'];
49 49
50 - self::assertArrayHasKey('init', $actions);
51 - self::assertSame([$runner, 'maybeDispatchAsyncRequest'], $actions['init'][0]['callback']);
52 - self::assertSame(10, $actions['init'][0]['priority']);
53 - self::assertSame(0, $actions['init'][0]['accepted_args']);
54 - self::assertArrayNotHasKey('shutdown', $actions);
50 + self::assertArrayHasKey('shutdown', $actions);
51 + self::assertSame([$runner, 'maybeDispatchAsyncRequest'], $actions['shutdown'][0]['callback']);
52 + self::assertSame(PHP_INT_MAX, $actions['shutdown'][0]['priority']);
53 + self::assertSame(1, $actions['shutdown'][0]['accepted_args']);
54 + self::assertArrayNotHasKey('init', $actions);
55 55
56 56 self::assertSame(
57 57 [$runner, 'maybeDispatchAsyncRequest'],
58 58 $actions['sync_basalam_job_created'][0]['callback']
@@ -64,9 +64,9 @@
64 64 $actions['wp_ajax_nopriv_' . self::ASYNC_ACTION][0]['callback']
65 65 );
66 66 }
67 67
68 - public function testEligibleQueueIsConfirmedBeforeWritingLockAndDispatching(): void
68 + public function testDispatchLeaseIsWrittenBeforeQueueProbeAndDispatching(): void
69 69 {
70 70 $jobManager = new FakeJobManager([true]);
71 71 $runner = $this->newRunner($jobManager);
72 72
@@ -73,9 +73,9 @@
73 73 $_COOKIE = ['wordpress_test_cookie' => 'cookie-value'];
74 74 $runner->maybeDispatchAsyncRequest();
75 75
76 76 self::assertSame(
77 - ['get_transient', 'has_pending_jobs', 'set_transient', 'remote_post'],
77 + ['get_transient', 'set_transient', 'has_pending_jobs', 'remote_post'],
78 78 $this->state()['events']
79 79 );
80 80 self::assertSame([120], $jobManager->timeouts);
81 81 self::assertSame(
@@ -99,9 +99,9 @@
99 99 self::assertSame('test-nonce-for-' . self::ASYNC_ACTION, $requests[0]['args']['body']['nonce']);
100 100 self::assertSame($_COOKIE, $requests[0]['args']['cookies']);
101 101 }
102 102
103 - public function testEmptyQueueDoesNotWriteLockOrDispatch(): void
103 + public function testEmptyQueueStillReservesDispatchLease(): void
104 104 {
105 105 $jobManager = new FakeJobManager([false]);
106 106 $runner = $this->newRunner($jobManager);
107 107
@@ -106,29 +106,36 @@
106 106 $runner = $this->newRunner($jobManager);
107 107
108 108 $runner->maybeDispatchAsyncRequest();
109 109
110 - self::assertSame(['get_transient', 'has_pending_jobs'], $this->state()['events']);
110 + self::assertSame(['get_transient', 'set_transient', 'has_pending_jobs'], $this->state()['events']);
111 111 self::assertSame([120], $jobManager->timeouts);
112 - self::assertSame([], $this->state()['transient_writes']);
112 + self::assertSame(
113 + [[
114 + 'name' => self::DISPATCH_LOCK,
115 + 'value' => 1,
116 + 'expiration' => 25,
117 + ]],
118 + $this->state()['transient_writes']
119 + );
113 120 self::assertSame([], $this->state()['remote_requests']);
114 121 }
115 122
116 - public function testJobCreatedAfterAnEmptyInitCanStillDispatch(): void
123 + public function testEmptyQueueLeasePreventsASecondProbeInTheSameRequest(): void
117 124 {
118 125 $jobManager = new FakeJobManager([false, true]);
119 126 $runner = $this->newRunner($jobManager);
120 127
121 - // The init probe sees no work and must not reserve the dispatch lock.
128 + // The shutdown probe reserves the lease even when no work is found.
122 129 $runner->maybeDispatchAsyncRequest();
123 - self::assertSame([], $this->state()['transient_writes']);
130 + self::assertCount(1, $this->state()['transient_writes']);
124 131
125 - // A job created later in the same request must still wake the runner.
132 + // A second callback in the same request must observe that lease.
126 133 $runner->maybeDispatchAsyncRequest();
127 134
128 - self::assertSame([120, 120], $jobManager->timeouts);
135 + self::assertSame([120], $jobManager->timeouts);
129 136 self::assertCount(1, $this->state()['transient_writes']);
130 - self::assertCount(1, $this->state()['remote_requests']);
137 + self::assertCount(0, $this->state()['remote_requests']);
131 138 }
132 139
133 140 public function testExistingLockSkipsQueueCheckAndDispatch(): void
134 141 {
@@ -167,22 +174,8 @@
167 174
168 175 $runner->maybeDispatchAsyncRequest();
169 176
170 177 self::assertSame(1, $httpBlockService->calls);
171 - $this->assertNoQueueLockOrDispatchActivity($jobManager);
172 - }
173 -
174 - public function testShutdownGuardPreventsEveryDispatchSideEffect(): void
175 - {
176 - $GLOBALS['sync_basalam_jobs_runner_test_state']['did_actions']['shutdown'] = 1;
177 -
178 - $jobManager = new FakeJobManager([true]);
179 - $httpBlockService = new FakeHttpBlockService(false);
180 - $runner = $this->newRunner($jobManager, $httpBlockService);
181 -
182 - $runner->maybeDispatchAsyncRequest();
183 -
184 - self::assertSame(0, $httpBlockService->calls);
185 178 $this->assertNoQueueLockOrDispatchActivity($jobManager);
186 179 }
187 180
188 181 public function testAsyncBatchExitsImmediatelyWhenAnotherRunnerOwnsTheGlobalLock(): void