From 48698f40badfc920929c2bf53903e14593d07544 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 21 Feb 2026 03:12:44 +1300 Subject: [PATCH] fix: add polling and delay for testSSRLogs logging config propagation After setting logging=false, the site runtime may not immediately pick up the config change. Add a 5s delay and poll for the NEW log entry (filtering out the old one by $id) to avoid picking up stale log entries with content. Co-Authored-By: Claude Opus 4.6 --- .../Services/Sites/SitesCustomServerTest.php | 77 +++++++++++++------ 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 04103b1659..161e37382e 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2150,41 +2150,68 @@ class SitesCustomServerTest extends Scope ] ); $this->assertEquals(200, $site['headers']['status-code']); + + // Wait for the logging config change to propagate to the site runtime + \sleep(5); + $response = $proxyClient->call(Client::METHOD_GET, '/logs-inline'); $this->assertEquals(200, $response['headers']['status-code']); $this->assertStringContainsString("Inline logs printed.", $response['body']); - $logs = $this->listLogs($siteId, [ - Query::orderDesc('$createdAt')->toString(), - Query::equal('requestPath', ['/logs-inline'])->toString(), - Query::limit(1)->toString(), - ]); - $this->assertEquals(200, $logs['headers']['status-code']); - $this->assertEquals("GET", $logs['body']['executions'][0]['requestMethod']); - $this->assertEquals("/logs-inline", $logs['body']['executions'][0]['requestPath']); - $this->assertEmpty($logs['body']['executions'][0]['logs']); - $this->assertEmpty($logs['body']['executions'][0]['logs']); - $this->assertEmpty($logs['body']['executions'][0]['errors']); - $this->assertEmpty($logs['body']['executions'][0]['errors']); - $log1Id = $logs['body']['executions'][0]['$id']; + // Poll for the NEW log entry (after logging was disabled) to appear + $timeout = 30; + $start = \time(); + $newLog = null; + while (\time() - $start < $timeout) { + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::equal('requestPath', ['/logs-inline'])->toString(), + Query::limit(1)->toString(), + ]); + if ( + !empty($logs['body']['executions']) && + $logs['body']['executions'][0]['$id'] !== $log1Id + ) { + $newLog = $logs['body']['executions'][0]; + break; + } + \sleep(1); + } + $this->assertNotNull($newLog, 'New log entry should appear after logging-disabled request'); + $this->assertEquals("GET", $newLog['requestMethod']); + $this->assertEquals("/logs-inline", $newLog['requestPath']); + $this->assertEmpty($newLog['logs']); + $this->assertEmpty($newLog['errors']); + $log1Id = $newLog['$id']; $this->assertNotEmpty($log1Id); $response = $proxyClient->call(Client::METHOD_GET, '/logs-action'); $this->assertEquals(200, $response['headers']['status-code']); $this->assertStringContainsString("Action logs printed.", $response['body']); - $logs = $this->listLogs($siteId, [ - Query::orderDesc('$createdAt')->toString(), - Query::equal('requestPath', ['/logs-action'])->toString(), - Query::limit(1)->toString(), - ]); - $this->assertEquals(200, $logs['headers']['status-code']); - $this->assertEquals("GET", $logs['body']['executions'][0]['requestMethod']); - $this->assertEquals("/logs-action", $logs['body']['executions'][0]['requestPath']); - $this->assertEmpty($logs['body']['executions'][0]['logs']); - $this->assertEmpty($logs['body']['executions'][0]['logs']); - $this->assertEmpty($logs['body']['executions'][0]['errors']); - $this->assertEmpty($logs['body']['executions'][0]['errors']); + // Poll for the NEW log entry for /logs-action + $start = \time(); + $newLog = null; + while (\time() - $start < $timeout) { + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::equal('requestPath', ['/logs-action'])->toString(), + Query::limit(1)->toString(), + ]); + if ( + !empty($logs['body']['executions']) && + $logs['body']['executions'][0]['$id'] !== $log2Id + ) { + $newLog = $logs['body']['executions'][0]; + break; + } + \sleep(1); + } + $this->assertNotNull($newLog, 'New log entry should appear after logging-disabled /logs-action request'); + $this->assertEquals("GET", $newLog['requestMethod']); + $this->assertEquals("/logs-action", $newLog['requestPath']); + $this->assertEmpty($newLog['logs']); + $this->assertEmpty($newLog['errors']); $log2Id = $logs['body']['executions'][0]['$id']; $this->assertNotEmpty($log2Id);