@@ -274,4 +274,50 @@ public function testCreationStats() {
274274 );
275275
276276 }
277+
278+ public function testPrepareStatsTreatsSecondPrecisionTimestampAtThresholdAsActive () {
279+ $ currentTime = CarbonImmutable::now ();
280+
281+ $ wiki = Wiki::factory ()->create (['deleted_at ' => null , 'domain ' => 'thresholdtest.com ' ]);
282+ WikiDb::create ([
283+ 'name ' => 'mwdb_threshold_ ' . $ wiki ->id ,
284+ 'user ' => 'user ' ,
285+ 'password ' => 'password ' ,
286+ 'version ' => 'version ' ,
287+ 'prefix ' => 'prefix ' ,
288+ 'wiki_id ' => $ wiki ->id ,
289+ ]);
290+
291+ Http::fake ([
292+ $ this ->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=122&apcontinue=&aplimit=max&format=json ' => Http::response ([
293+ 'query ' => ['allpages ' => []],
294+ ], 200 ),
295+ $ this ->mwBackendHost . '/w/api.php?action=query&list=allpages&apnamespace=120&apcontinue=&aplimit=max&format=json ' => Http::response ([
296+ 'query ' => ['allpages ' => []],
297+ ], 200 ),
298+ ]);
299+
300+ $ job = new PlatformStatsSummaryJob ;
301+ (function ($ resolver ): void {
302+ $ this ->mwHostResolver = $ resolver ;
303+ })->call ($ job , $ this ->mockMwHostResolver );
304+
305+ $ groups = $ job ->prepareStats ([
306+ [
307+ 'wiki ' => 'thresholdtest.com ' ,
308+ 'edits ' => 1 ,
309+ 'pages ' => 1 ,
310+ 'users ' => 1 ,
311+ 'active_users ' => 1 ,
312+ 'lastEdit ' => MWTimestampHelper::getMWTimestampFromCarbon (
313+ $ currentTime ->subSeconds (config ('wbstack.platform_summary_inactive_threshold ' ))
314+ ),
315+ 'first100UsingOauth ' => '0 ' ,
316+ 'platform_summary_version ' => 'v1 ' ,
317+ ],
318+ ], [$ wiki ]);
319+
320+ $ this ->assertSame (1 , $ groups ['edited_last_90_days ' ]);
321+ $ this ->assertSame (0 , $ groups ['not_edited_last_90_days ' ]);
322+ }
277323}
0 commit comments