feat(seo): 사이트맵 재생성 진행상황 + 실시간/폴링 UI
관리자 "전체 재생성"을 큐(Full 모드)로 던지고 진행상황을 SEO 탭에서 확인한다. Reverb ON 이면 방송 채널 구독으로 실시간 갱신, OFF 면 상태 API 폴링으로 폴백한다. - SitemapProgress 진행상황 스토어(queued→running→writing→completed/failed, 캐시 TTL 3600, 방송 스로틀) + SitemapManager.getStatus 확장(progress + realtime_enabled) - GET /api/admin/seo/sitemap/status(core.settings.read) 신규 - 관리자 재생성을 항상 Full 모드로 큐잉 + 진행률 기록, Job 최종 실패 시 progress=failed 고정 - core.admin.seo.sitemap 방송 채널 인증(core.settings.read) - SEO 탭 진행상황 UI(상태 배지/단계/누적 URL/실시간·폴링 안내) + 폴링 분기 - 재생성 중 누적 URL 표기(replaceAllForContributor 삽입 건수 반환 — count 쿼리 없이 스트림 누적) - ja 언어팩 진행상황 UI 번역 동기화
This commit is contained in:
1 parent
1629684156
commit
face022073
29 files changed
+1145
-83
No files matched your search
@@ -3,7 +3,9 @@
|
||||
namespace Tests\Feature\Api\Admin;
|
||||
|
||||
use App\Enums\ExtensionOwnerType;
|
||||
use App\Enums\SitemapGenerationMode;
|
||||
use App\Jobs\GenerateSitemapJob;
|
||||
use App\Seo\SitemapProgress;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\SeoCacheStat;
|
||||
@@ -392,27 +394,33 @@ class SeoCacheControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* 재생성 요청 시 200 + 예약 상태와 직전 생성 시각을 반환
|
||||
* 재생성 요청 시 200 + 진행상황(queued)과 직전 생성 시각을 반환
|
||||
*/
|
||||
public function test_regenerate_sitemap_returns_200_with_dispatched_status(): void
|
||||
public function test_regenerate_sitemap_returns_200_with_queued_progress(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Config::set('g7_settings.core.seo.sitemap_enabled', true);
|
||||
Config::set('g7_settings.core.seo.sitemap_last_updated_at', '2026-04-29T10:00:00+00:00');
|
||||
// realtime_enabled 판정을 결정적으로: 웹소켓 OFF → false
|
||||
Config::set('broadcasting.default', 'null');
|
||||
|
||||
$response = $this->withHeader('Authorization', 'Bearer '.$this->token)
|
||||
->postJson('/api/admin/seo/sitemap/regenerate');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$this->assertTrue($response->json('success'));
|
||||
$this->assertSame('dispatched', $response->json('data.status'));
|
||||
$this->assertSame('queued', $response->json('data.progress.status'));
|
||||
$this->assertSame('full', $response->json('data.progress.mode'));
|
||||
$this->assertSame('2026-04-29T10:00:00+00:00', $response->json('data.last_updated_at'));
|
||||
$this->assertFalse($response->json('data.realtime_enabled'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 재생성 요청이 큐 잡을 1건만 디스패치하는지 확인
|
||||
* 재생성 요청이 큐 잡을 1건만, 항상 전체(Full) 모드로 디스패치하는지 확인
|
||||
*
|
||||
* 관리자 수동 재생성은 현 생성 상태와 무관하게 항상 전량 재생성입니다(D7).
|
||||
*/
|
||||
public function test_regenerate_sitemap_dispatches_job(): void
|
||||
public function test_regenerate_sitemap_dispatches_full_mode_job(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Config::set('g7_settings.core.seo.sitemap_enabled', true);
|
||||
@@ -422,6 +430,10 @@ class SeoCacheControllerTest extends TestCase
|
||||
->assertStatus(200);
|
||||
|
||||
Queue::assertPushed(GenerateSitemapJob::class, 1);
|
||||
Queue::assertPushed(
|
||||
GenerateSitemapJob::class,
|
||||
fn (GenerateSitemapJob $job) => $job->mode === SitemapGenerationMode::Full
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,6 +472,87 @@ class SeoCacheControllerTest extends TestCase
|
||||
Queue::assertNotPushed(GenerateSitemapJob::class);
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Sitemap 진행상황 조회 (sitemapStatus)
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 인증 없이 sitemap 상태 조회 시 401 반환
|
||||
*/
|
||||
public function test_sitemap_status_returns_401_without_authentication(): void
|
||||
{
|
||||
$response = $this->getJson('/api/admin/seo/sitemap/status');
|
||||
|
||||
$response->assertStatus(401);
|
||||
}
|
||||
|
||||
/**
|
||||
* read 권한만 있어도 sitemap 상태 조회 가능 (SEO 탭 읽기 권한)
|
||||
*/
|
||||
public function test_sitemap_status_allows_read_permission(): void
|
||||
{
|
||||
$user = $this->createAdminUser(['core.settings.read']);
|
||||
$token = $user->createToken('test-token')->plainTextToken;
|
||||
|
||||
$response = $this->withToken($token)->getJson('/api/admin/seo/sitemap/status');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* 상태 조회 응답이 진행상황 + realtime_enabled 스키마를 포함
|
||||
*/
|
||||
public function test_sitemap_status_returns_progress_and_realtime_flag(): void
|
||||
{
|
||||
// 진행상황을 미리 기록
|
||||
app(SitemapProgress::class)->start(SitemapGenerationMode::Full->value);
|
||||
// realtime_enabled 판정을 결정적으로: 웹소켓 OFF → false
|
||||
Config::set('broadcasting.default', 'null');
|
||||
|
||||
$response = $this->withToken($this->token)->getJson('/api/admin/seo/sitemap/status');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonStructure([
|
||||
'success',
|
||||
'data' => [
|
||||
'last_updated_at',
|
||||
'progress' => ['status', 'mode'],
|
||||
'realtime_enabled',
|
||||
],
|
||||
]);
|
||||
$this->assertSame('queued', $response->json('data.progress.status'));
|
||||
$this->assertFalse($response->json('data.realtime_enabled'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 진행상황이 없으면 progress 는 null
|
||||
*/
|
||||
public function test_sitemap_status_returns_null_progress_when_idle(): void
|
||||
{
|
||||
$response = $this->withToken($this->token)->getJson('/api/admin/seo/sitemap/status');
|
||||
|
||||
$response->assertStatus(200);
|
||||
$this->assertNull($response->json('data.progress'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 재생성 요청이 진행상황을 'queued' 로 즉시 기록 (큐 대기 중에도 UI 표시)
|
||||
*/
|
||||
public function test_regenerate_sitemap_records_queued_progress(): void
|
||||
{
|
||||
Queue::fake();
|
||||
Config::set('g7_settings.core.seo.sitemap_enabled', true);
|
||||
|
||||
$this->withHeader('Authorization', 'Bearer '.$this->token)
|
||||
->postJson('/api/admin/seo/sitemap/regenerate')
|
||||
->assertStatus(200);
|
||||
|
||||
$progress = app(SitemapProgress::class)->get();
|
||||
$this->assertNotNull($progress);
|
||||
$this->assertSame('queued', $progress['status']);
|
||||
$this->assertSame('full', $progress['mode']);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Tests\Feature\Api;
|
||||
|
||||
use App\Enums\ExtensionOwnerType;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
@@ -74,4 +77,93 @@ class BroadcastingAuthTest extends TestCase
|
||||
// 토글 OFF 가 아님을 확인: 401(미인증) 이 아닌 것으로 인증 통과 입증.
|
||||
$this->assertNotSame(401, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sitemap 진행상황 채널이 등록되어 있고, core.settings.read 권한 보유 시 인증을 허용한다.
|
||||
*
|
||||
* broadcasting/auth HTTP 엔드포인트는 이 하네스에서 서명 응답을 낼 수 없어(권한 유무와 무관하게 403)
|
||||
* 인증 여부를 구분하지 못하므로, 등록된 채널 콜백을 직접 호출해 인가 로직을 검증한다.
|
||||
*/
|
||||
public function test_sitemap_channel_authorizes_user_with_settings_read(): void
|
||||
{
|
||||
$callback = $this->channelCallback('core.admin.seo.sitemap');
|
||||
|
||||
$user = $this->userWithPermission('core.settings.read');
|
||||
|
||||
$this->assertTrue((bool) $callback($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sitemap 진행상황 채널: core.settings.read 권한 미보유 시 거부.
|
||||
*/
|
||||
public function test_sitemap_channel_rejects_user_without_permission(): void
|
||||
{
|
||||
$callback = $this->channelCallback('core.admin.seo.sitemap');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->assertFalse((bool) $callback($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* 등록된 브로드캐스트 채널의 인가 콜백을 반환합니다.
|
||||
*
|
||||
* @param string $channel 채널명 (private- 접두 없이)
|
||||
* @return \Closure 인가 콜백 (첫 인자 = 사용자)
|
||||
*/
|
||||
private function channelCallback(string $channel): \Closure
|
||||
{
|
||||
$broadcaster = app(\Illuminate\Contracts\Broadcasting\Factory::class)->connection();
|
||||
|
||||
$ref = new \ReflectionClass($broadcaster);
|
||||
while ($ref !== false && ! $ref->hasProperty('channels')) {
|
||||
$ref = $ref->getParentClass();
|
||||
}
|
||||
$this->assertNotFalse($ref, 'broadcaster 에 channels 프로퍼티가 없음');
|
||||
|
||||
$prop = $ref->getProperty('channels');
|
||||
$prop->setAccessible(true);
|
||||
$channels = $prop->getValue($broadcaster);
|
||||
|
||||
$this->assertArrayHasKey($channel, $channels, "채널이 등록되지 않음: {$channel}");
|
||||
|
||||
return $channels[$channel];
|
||||
}
|
||||
|
||||
/**
|
||||
* 지정한 관리자 권한을 가진 사용자를 생성합니다.
|
||||
*
|
||||
* @param string $permission 권한 식별자
|
||||
* @return User 권한이 부여된 사용자
|
||||
*/
|
||||
private function userWithPermission(string $permission): User
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$perm = Permission::firstOrCreate(
|
||||
['identifier' => $permission],
|
||||
[
|
||||
'name' => json_encode(['ko' => $permission, 'en' => $permission]),
|
||||
'description' => json_encode(['ko' => $permission, 'en' => $permission]),
|
||||
'extension_type' => ExtensionOwnerType::Core,
|
||||
'extension_identifier' => 'core',
|
||||
'type' => 'admin',
|
||||
]
|
||||
);
|
||||
|
||||
$role = Role::create([
|
||||
'identifier' => 'sitemap_channel_test_'.uniqid(),
|
||||
'name' => json_encode(['ko' => '테스트', 'en' => 'Test']),
|
||||
'description' => json_encode(['ko' => '테스트', 'en' => 'Test']),
|
||||
'is_active' => true,
|
||||
]);
|
||||
$role->permissions()->sync([$perm->id]);
|
||||
|
||||
$user->roles()->attach($role->id, [
|
||||
'assigned_at' => now(),
|
||||
'assigned_by' => null,
|
||||
]);
|
||||
|
||||
return $user->fresh();
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,7 @@ class SitemapManagerModeTest extends TestCase
|
||||
Mockery::spy(ConfigRepositoryInterface::class),
|
||||
$this->storage,
|
||||
$this->repository,
|
||||
$this->app->make(\App\Seo\SitemapProgress::class),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -156,6 +156,30 @@ class SitemapUrlRepositoryTest extends TestCase
|
||||
$this->assertSame(['https://example.com/page/a'], $page, '다른 기여자 행은 보존돼야 합니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* replaceAllForContributor 는 삽입된 행 수를 반환한다 (진행상황 누적 URL 표기용).
|
||||
*
|
||||
* 청크 경계를 넘겨도 정확히 집계돼야 한다 (INSERT_CHUNK=1000 이므로 2건은 단일 청크지만
|
||||
* 반환 계약 자체를 고정한다).
|
||||
*/
|
||||
public function test_replace_all_for_contributor_returns_inserted_count(): void
|
||||
{
|
||||
$count = $this->repository->replaceAllForContributor('sirsoft-board', [
|
||||
['loc' => 'https://example.com/board/a', 'resource_type' => 'board', 'resource_id' => '1'],
|
||||
['loc' => 'https://example.com/board/a/1', 'resource_type' => 'board_post', 'resource_id' => '1'],
|
||||
['loc' => 'https://example.com/board/a/2', 'resource_type' => 'board_post', 'resource_id' => '2'],
|
||||
]);
|
||||
|
||||
$this->assertSame(3, $count);
|
||||
|
||||
// 재대체 시에도 새로 삽입된 건수를 반환 (기존 삭제분은 제외)
|
||||
$recount = $this->repository->replaceAllForContributor('sirsoft-board', [
|
||||
['loc' => 'https://example.com/board/b', 'resource_type' => 'board', 'resource_id' => '2'],
|
||||
]);
|
||||
|
||||
$this->assertSame(1, $recount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 긴 loc(2000자) 도 loc_hash 로 안전 저장 및 식별된다 (MySQL 키 길이 회피).
|
||||
*/
|
||||
|
||||
@@ -78,11 +78,14 @@ test('#481 - hreflang 토글을 바꿔 저장하면 성공하고 재진입 시
|
||||
|
||||
const toggle = page.locator(`${HREFLANG_ROW} input[type="checkbox"]`).first();
|
||||
await expect(toggle).toBeAttached({ timeout: 15_000 });
|
||||
// 체크박스 input 은 sr-only(화면에서 숨김)이고 클릭 대상은 wrapper div(onClick) 이다.
|
||||
// input 을 직접 클릭하면 toggle-switch-track 오버레이가 포인터 이벤트를 가로챈다.
|
||||
const toggleSwitch = page.locator(`${HREFLANG_ROW} .toggle-switch-wrapper`).first();
|
||||
|
||||
const wasChecked = await toggle.isChecked();
|
||||
|
||||
// 토글을 반대 상태로 바꾼다
|
||||
await toggle.click();
|
||||
await toggleSwitch.click();
|
||||
await expect(page.locator('#save_button')).toBeEnabled({ timeout: 10_000 });
|
||||
|
||||
const save = page.waitForResponse(
|
||||
@@ -99,7 +102,7 @@ test('#481 - hreflang 토글을 바꿔 저장하면 성공하고 재진입 시
|
||||
await expect.poll(() => reloaded.isChecked(), { timeout: 15_000 }).toBe(!wasChecked);
|
||||
|
||||
// 원상 복구 (E2E 는 실제 환경 설정을 건드린다)
|
||||
await reloaded.click();
|
||||
await page.locator(`${HREFLANG_ROW} .toggle-switch-wrapper`).first().click();
|
||||
const restore = page.waitForResponse(
|
||||
(r) => r.url().includes('/api/admin/settings') && r.request().method() === 'POST',
|
||||
{ timeout: 20_000 }
|
||||
@@ -197,8 +200,8 @@ test('#481 - 고급 탭 Sitemap 캐시 기준값 칸이 마운트되고 기본
|
||||
});
|
||||
|
||||
// @scenario tab=seo, permitted=yes
|
||||
// @effects regenerate_is_async
|
||||
test('#481 - "지금 생성" 클릭이 큐에 예약되고 즉시 응답한다', async ({ page }) => {
|
||||
// @effects regenerate_is_async, progress_visible
|
||||
test('#481 - "지금 생성" 클릭이 큐에 예약되고 진행상황이 화면에 표시된다', async ({ page }) => {
|
||||
const token = issueToken('core.settings.read', 'core.settings.update');
|
||||
await authenticatePage(page, token);
|
||||
|
||||
@@ -215,9 +218,39 @@ test('#481 - "지금 생성" 클릭이 큐에 예약되고 즉시 응답한다',
|
||||
const elapsed = Date.now() - startedAt;
|
||||
|
||||
expect(response.status()).toBe(200);
|
||||
expect((await response.json())?.data?.status).toBe('dispatched');
|
||||
// 예약 즉시 진행상황이 'queued' 로 실려 온다 (동기 생성이 아니라 큐 예약)
|
||||
expect((await response.json())?.data?.progress?.status).toBe('queued');
|
||||
|
||||
// 동기 생성으로 되돌아가면 응답 시간이 데이터 규모에 비례해 늘어난다.
|
||||
// 절대 하한 대신 "예약 응답이라면 당연히 만족하는" 상한으로 회귀만 잡는다.
|
||||
expect(elapsed).toBeLessThan(10_000);
|
||||
|
||||
// 진행상황 블록이 화면에 나타나고 상태 배지가 미해석 키가 아닌 실제 문구로 렌더된다
|
||||
const progressBlock = page.locator('#sitemap_progress_block');
|
||||
await expect(progressBlock).toBeAttached({ timeout: 15_000 });
|
||||
const progressText = (await progressBlock.innerText()).trim();
|
||||
expect(progressText).not.toContain('$t:');
|
||||
expect(progressText.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// @scenario tab=seo, permitted=yes
|
||||
// @effects status_endpoint
|
||||
test('#481 - SEO 탭 진입 시 sitemap 상태 API 가 진행상황/실시간 여부를 반환한다', async ({ page }) => {
|
||||
const token = issueToken('core.settings.read', 'core.settings.update');
|
||||
await authenticatePage(page, token);
|
||||
|
||||
const status = page.waitForResponse(
|
||||
(r) => r.url().includes('/api/admin/seo/sitemap/status') && r.request().method() === 'GET',
|
||||
{ timeout: 20_000 }
|
||||
);
|
||||
|
||||
await gotoSeoTab(page);
|
||||
|
||||
const res = await status;
|
||||
expect(res.status()).toBe(200);
|
||||
const body = await res.json();
|
||||
// 상태 응답 스키마: 진행상황(progress) + 실시간 연결 가능 여부(realtime_enabled)
|
||||
expect(body?.data).toHaveProperty('realtime_enabled');
|
||||
expect(body?.data).toHaveProperty('progress');
|
||||
expect(body?.data).toHaveProperty('last_updated_at');
|
||||
});
|
||||
@@ -133,6 +133,7 @@ class SitemapManagerTest extends TestCase
|
||||
$config ?? Mockery::spy(ConfigRepositoryInterface::class),
|
||||
$this->storage,
|
||||
$this->app->make(SitemapUrlRepositoryInterface::class),
|
||||
$this->app->make(\App\Seo\SitemapProgress::class),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -312,6 +313,7 @@ class SitemapManagerTest extends TestCase
|
||||
Mockery::spy(ConfigRepositoryInterface::class),
|
||||
$this->storage,
|
||||
$this->incrementalRepository(),
|
||||
$this->app->make(\App\Seo\SitemapProgress::class),
|
||||
);
|
||||
|
||||
$result = $manager->regenerate();
|
||||
@@ -343,6 +345,7 @@ class SitemapManagerTest extends TestCase
|
||||
Mockery::spy(ConfigRepositoryInterface::class),
|
||||
$this->storage,
|
||||
$this->incrementalRepository(),
|
||||
$this->app->make(\App\Seo\SitemapProgress::class),
|
||||
);
|
||||
|
||||
$this->assertFalse($manager->regenerate()['success']);
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Seo;
|
||||
|
||||
use App\Events\GenericBroadcastEvent;
|
||||
use App\Seo\SitemapProgress;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* SitemapProgress 진행상황 스토어 테스트
|
||||
*
|
||||
* 상태 전이(queued→running→writing→completed|failed), 캐시 기록, 방송(Reverb ON),
|
||||
* 방송 스로틀(N URL 간격), Reverb OFF 시 캐시 폴백을 검증합니다.
|
||||
*/
|
||||
class SitemapProgressTest extends TestCase
|
||||
{
|
||||
private SitemapProgress $progress;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->progress = app(SitemapProgress::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverb 방송이 실제로 발생하도록 드라이버/호스트를 설정합니다.
|
||||
*/
|
||||
private function enableReverb(): void
|
||||
{
|
||||
config(['broadcasting.default' => 'reverb']);
|
||||
config(['broadcasting.connections.reverb.options.host' => 'localhost']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 실행 이력이 없으면 get() 은 null 을 반환한다.
|
||||
*/
|
||||
public function test_get_returns_null_when_no_run(): void
|
||||
{
|
||||
$this->assertNull($this->progress->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* start() 는 status=queued 와 mode/started_at 을 기록한다.
|
||||
*/
|
||||
public function test_start_records_queued_state(): void
|
||||
{
|
||||
$this->progress->start('full');
|
||||
|
||||
$state = $this->progress->get();
|
||||
$this->assertSame('queued', $state['status']);
|
||||
$this->assertSame('full', $state['mode']);
|
||||
$this->assertNotNull($state['started_at']);
|
||||
$this->assertSame(0, $state['urls']);
|
||||
}
|
||||
|
||||
/**
|
||||
* phase() 는 status=running 과 현재 단계를 기록한다.
|
||||
*/
|
||||
public function test_phase_records_running_state(): void
|
||||
{
|
||||
$this->progress->start('full');
|
||||
$this->progress->phase('sirsoft-board', 1200);
|
||||
|
||||
$state = $this->progress->get();
|
||||
$this->assertSame('running', $state['status']);
|
||||
$this->assertSame('sirsoft-board', $state['phase']);
|
||||
$this->assertSame(1200, $state['urls']);
|
||||
}
|
||||
|
||||
/**
|
||||
* writing() 은 status=writing 을 기록한다.
|
||||
*/
|
||||
public function test_writing_records_writing_state(): void
|
||||
{
|
||||
$this->progress->start('full');
|
||||
$this->progress->writing(3400);
|
||||
|
||||
$state = $this->progress->get();
|
||||
$this->assertSame('writing', $state['status']);
|
||||
$this->assertSame(3400, $state['urls']);
|
||||
}
|
||||
|
||||
/**
|
||||
* complete() 는 status=completed 와 url_count/child_count 를 기록한다.
|
||||
*/
|
||||
public function test_complete_records_completed_state(): void
|
||||
{
|
||||
$this->progress->start('full');
|
||||
$this->progress->complete(['url_count' => 5000, 'child_count' => 2]);
|
||||
|
||||
$state = $this->progress->get();
|
||||
$this->assertSame('completed', $state['status']);
|
||||
$this->assertSame(5000, $state['url_count']);
|
||||
$this->assertSame(2, $state['child_count']);
|
||||
$this->assertNotNull($state['finished_at']);
|
||||
}
|
||||
|
||||
/**
|
||||
* fail() 은 status=failed 와 메시지를 기록한다.
|
||||
*/
|
||||
public function test_fail_records_failed_state(): void
|
||||
{
|
||||
$this->progress->start('full');
|
||||
$this->progress->fail('boom');
|
||||
|
||||
$state = $this->progress->get();
|
||||
$this->assertSame('failed', $state['status']);
|
||||
$this->assertSame('boom', $state['message']);
|
||||
$this->assertNotNull($state['finished_at']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverb ON 이면 방송 payload 가 상태 API data 형태(progress + realtime_enabled)와 동형이다.
|
||||
*/
|
||||
public function test_broadcast_payload_mirrors_status_shape(): void
|
||||
{
|
||||
$this->enableReverb();
|
||||
Event::fake([GenericBroadcastEvent::class]);
|
||||
|
||||
$this->progress->start('full');
|
||||
|
||||
Event::assertDispatched(GenericBroadcastEvent::class, function ($event) {
|
||||
return $event->channel === 'core.admin.seo.sitemap'
|
||||
&& $event->eventName === 'sitemap.progress.updated'
|
||||
&& ($event->payload['realtime_enabled'] ?? null) === true
|
||||
&& ($event->payload['progress']['status'] ?? null) === 'queued';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverb OFF 여도 캐시는 기록된다(폴링 폴백 성립).
|
||||
*/
|
||||
public function test_cache_is_written_even_when_reverb_off(): void
|
||||
{
|
||||
config(['broadcasting.default' => 'null']);
|
||||
Event::fake([GenericBroadcastEvent::class]);
|
||||
|
||||
$this->progress->start('full');
|
||||
|
||||
Event::assertNotDispatched(GenericBroadcastEvent::class);
|
||||
$this->assertSame('queued', $this->progress->get()['status']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 같은 단계에서 urls 만 증가하면 방송은 간격 스로틀되지만 캐시는 항상 기록된다.
|
||||
*/
|
||||
public function test_phase_broadcast_is_throttled_but_cache_always_written(): void
|
||||
{
|
||||
$this->enableReverb();
|
||||
Event::fake([GenericBroadcastEvent::class]);
|
||||
|
||||
// 단계 진입 — 방송 1회
|
||||
$this->progress->phase('sirsoft-board', 100);
|
||||
// 같은 단계, 소폭 증가(<5000) — 방송 스킵, 캐시는 갱신
|
||||
$this->progress->phase('sirsoft-board', 200);
|
||||
// 같은 단계, 간격 초과(>=5000) — 방송 재발
|
||||
$this->progress->phase('sirsoft-board', 5300);
|
||||
|
||||
// 방송은 진입 + 간격초과 = 2회
|
||||
Event::assertDispatchedTimes(GenericBroadcastEvent::class, 2);
|
||||
// 캐시는 마지막 값으로 항상 갱신
|
||||
$this->assertSame(5300, $this->progress->get()['urls']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user