-
Notifications
You must be signed in to change notification settings - Fork 2
fix(presentations): resolve summit_id via owning presentation for PresentationMaterial lifecycle events #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
romanetar
wants to merge
2
commits into
main
Choose a base branch
from
fix/presentation-material-summit-id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
176 changes: 176 additions & 0 deletions
176
tests/Feature/PresentationMaterialRabbitMQIntegrationTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| <?php namespace Tests\Feature; | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Events\ScheduleEntityLifeCycleEvent; | ||
| use App\Jobs\ProcessScheduleEntityLifeCycleEvent; | ||
| use App\Services\Model\IProcessScheduleEntityLifeCycleEventService; | ||
| use Illuminate\Support\Facades\Config; | ||
| use PhpAmqpLib\Channel\AMQPChannel; | ||
| use PhpAmqpLib\Connection\AMQPStreamConnection; | ||
| use PhpAmqpLib\Exchange\AMQPExchangeType; | ||
| use Tests\InsertSummitTestData; | ||
| use Tests\TestCase; | ||
|
|
||
| /** | ||
| * Class PresentationMaterialRabbitMQIntegrationTest | ||
| * | ||
| * Full end-to-end coverage of the trace requested by the ticket: | ||
| * ScheduleEntityLifeCycleEvent -> EventServiceProvider listener -> job payload | ||
| * (already covered by PresentationMaterialEventDispatchTest via Queue::fake()) | ||
| * -> ProcessScheduleEntityLifeCycleEvent::handle() -> ProcessScheduleEntityLifeCycleEventService::process() | ||
| * -> RabbitPublisherService::publish() -> real message on the entities-updates-broker | ||
| * exchange. | ||
| * | ||
| * Runs the job for real (no Queue::fake()) against the actual RabbitMQ broker | ||
| * from docker-compose (rabbitmq_sponsor_services, reachable on the | ||
| * summit-api-local-net network the app container is also on) and asserts the | ||
| * published AMQP payload's summit_id is non-zero for a PresentationMediaUpload. | ||
| * | ||
| * @package Tests\Feature | ||
| */ | ||
| class PresentationMaterialRabbitMQIntegrationTest extends TestCase | ||
| { | ||
| use InsertSummitTestData; | ||
|
|
||
| const EXCHANGE = 'entities-updates-broker'; | ||
|
|
||
| private ?AMQPStreamConnection $consumer_connection = null; | ||
|
|
||
| private ?AMQPChannel $consumer_channel = null; | ||
|
|
||
| private ?string $consumer_queue = null; | ||
|
|
||
| /** | ||
| * @var array<string, mixed> | ||
| */ | ||
| private array $original_rabbitmq_config = []; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| self::insertSummitTestData(); | ||
|
|
||
| $this->original_rabbitmq_config = Config::get('rabbitmq'); | ||
|
|
||
| // The default rabbitmq.* config (RABBITMQ_HOST=host.docker.internal:5672) | ||
| // has nothing listening in this environment. Point it at the broker this | ||
| // container can actually reach, reusing the same credentials docker-compose | ||
| // already configures (as plain env vars, not literals) for rabbitmq_sponsor_services. | ||
| Config::set('rabbitmq.host', env('DOMAIN_EVENTS_RABBITMQ_HOST', 'rabbitmq_sponsor_services')); | ||
| Config::set('rabbitmq.port', 5672); | ||
| Config::set('rabbitmq.user', env('DOMAIN_EVENTS_RABBITMQ_LOGIN', env('RABBITMQ_LOGIN', 'guest'))); | ||
| Config::set('rabbitmq.password', env('DOMAIN_EVENTS_RABBITMQ_PASSWORD', env('RABBITMQ_PASSWORD', 'guest'))); | ||
| Config::set('rabbitmq.vhost', env('DOMAIN_EVENTS_RABBITMQ_VHOST', '/')); | ||
| // Force IProcessScheduleEntityLifeCycleEventService (a singleton) to | ||
| // rebuild its internal RabbitPublisherService against the config above, | ||
| // in case anything already resolved it with the default (unreachable) host. | ||
| app()->forgetInstance(IProcessScheduleEntityLifeCycleEventService::class); | ||
|
|
||
| $this->consumer_connection = new AMQPStreamConnection( | ||
| config('rabbitmq.host'), | ||
| config('rabbitmq.port'), | ||
| config('rabbitmq.user'), | ||
| config('rabbitmq.password'), | ||
| config('rabbitmq.vhost'), | ||
| ); | ||
| $this->consumer_channel = $this->consumer_connection->channel(); | ||
| // Must match the type/durable/auto_delete the real publisher declares with | ||
| // (RabbitPublisherService defaults: fanout, durable=true, auto_delete=false) | ||
| // or RabbitMQ rejects the redeclaration. | ||
| $this->consumer_channel->exchange_declare(self::EXCHANGE, AMQPExchangeType::FANOUT, false, true, false); | ||
| [$this->consumer_queue] = $this->consumer_channel->queue_declare('', false, false, true, true); | ||
| $this->consumer_channel->queue_bind($this->consumer_queue, self::EXCHANGE); | ||
| } | ||
|
|
||
| public function tearDown(): void | ||
| { | ||
| try { | ||
| $this->consumer_channel?->close(); | ||
| $this->consumer_connection?->close(); | ||
| } catch (\Throwable $ex) { | ||
| // best-effort cleanup | ||
| } | ||
| // Undo the setUp() overrides so later tests in this process see the | ||
| // original rabbitmq config and a fresh service singleton, not this | ||
| // test's real-broker configuration. | ||
| Config::set('rabbitmq', $this->original_rabbitmq_config); | ||
| app()->forgetInstance(IProcessScheduleEntityLifeCycleEventService::class); | ||
| self::clearSummitTestData(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| private function drainQueue(): void | ||
| { | ||
| while ($this->consumer_channel->basic_get($this->consumer_queue, true)) { | ||
| // discard any message left over from a previous run | ||
| } | ||
| } | ||
|
|
||
| public function testMediaUploadUpdateEndToEndPublishesNonZeroSummitId(): void | ||
| { | ||
| $media_upload = null; | ||
| foreach (self::$presentations as $presentation) { | ||
| $candidate = $presentation->getMediaUploads()->first(); | ||
| if ($candidate !== false) { | ||
| $media_upload = $candidate; | ||
| break; | ||
| } | ||
| } | ||
| $this->assertNotNull($media_upload, 'Pre-condition: fixtures must include a media upload'); | ||
|
|
||
| // Compute summit_id exactly the way ScheduleEntity's PostPersist/PostUpdate/ | ||
| // PreRemove hooks do (private _getSummitId(), resolved via reflection), | ||
| // instead of assuming PresentationMaterial::getSummitId() exists - so this | ||
| // test also fails meaningfully pre-fix (summit_id resolves to 0) rather | ||
| // than erroring on a missing method. | ||
| $rc = new \ReflectionClass($media_upload); | ||
| $get_summit_id = $rc->getMethod('_getSummitId'); | ||
| $get_summit_id->setAccessible(true); | ||
| $summit_id = $get_summit_id->invoke($media_upload); | ||
| $entity_id = $media_upload->getId(); | ||
| $this->assertGreaterThan(0, $summit_id, 'Pre-condition: presentation must belong to a summit, and _getSummitId() must resolve it (this is the exact bug being fixed)'); | ||
|
|
||
| $this->drainQueue(); | ||
|
|
||
| // Run the real job/service/publisher chain, exactly as the | ||
| // EventServiceProvider listener would when the queue worker picks it up. | ||
| $job = new ProcessScheduleEntityLifeCycleEvent( | ||
| ScheduleEntityLifeCycleEvent::Operation_Update, | ||
| $summit_id, | ||
| $entity_id, | ||
| 'PresentationMediaUpload' | ||
| ); | ||
| $job->handle(app(IProcessScheduleEntityLifeCycleEventService::class)); | ||
|
|
||
| // The queue is bound to the whole fanout exchange, so it can receive | ||
| // unrelated messages from other activity on the same broker. Skip past | ||
| // anything that isn't this update before asserting on it. | ||
| $payload = null; | ||
| for ($i = 0; $i < 30 && is_null($payload); $i++) { | ||
| $message = $this->consumer_channel->basic_get($this->consumer_queue, true); | ||
| if (is_null($message)) { | ||
| usleep(100000); | ||
| continue; | ||
| } | ||
| $candidate = json_decode($message->getBody(), true); | ||
| if (($candidate['entity_type'] ?? null) === 'PresentationMediaUpload' | ||
| && ($candidate['entity_id'] ?? null) === $entity_id) { | ||
| $payload = $candidate; | ||
| } | ||
| } | ||
|
|
||
| $this->assertNotNull($payload, 'Expected a PresentationMediaUpload message for this entity on the entities-updates-broker exchange'); | ||
| $this->assertSame($summit_id, $payload['summit_id'], 'Published summit_id must be the real summit id, not 0'); | ||
| } | ||
| } | ||
139 changes: 139 additions & 0 deletions
139
tests/Unit/Services/PresentationMaterialEventDispatchTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| <?php namespace Tests\Unit\Services; | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Jobs\ProcessScheduleEntityLifeCycleEvent; | ||
| use Illuminate\Support\Facades\Queue; | ||
| use models\summit\PresentationMediaUpload; | ||
| use Tests\InsertSummitTestData; | ||
| use Tests\TestCase; | ||
|
|
||
| /** | ||
| * Class PresentationMaterialEventDispatchTest | ||
| * | ||
| * Regression coverage for a bug where PresentationMaterial (PresentationMediaUpload, | ||
| * PresentationSlide, PresentationVideo, PresentationLink) lifecycle events were | ||
| * dispatched with summit_id => 0: ScheduleEntity::_getSummitId() resolves the | ||
| * summit id via reflection (a "summit" property, or a getSummitId() method), and | ||
| * PresentationMaterial exposed neither - it only has a "presentation" relation. | ||
| * The fix adds PresentationMaterial::getSummitId(), delegating to the owning | ||
| * Presentation. | ||
| * | ||
| * @package Tests\Unit\Services | ||
| */ | ||
| class PresentationMaterialEventDispatchTest extends TestCase | ||
| { | ||
| use InsertSummitTestData; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| self::insertSummitTestData(); | ||
| } | ||
|
|
||
| public function tearDown(): void | ||
| { | ||
| self::clearSummitTestData(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| private function getMediaUpload(): PresentationMediaUpload | ||
| { | ||
| foreach (self::$presentations as $presentation) { | ||
| $media_upload = $presentation->getMediaUploads()->first(); | ||
| if ($media_upload !== false) { | ||
| return $media_upload; | ||
| } | ||
| } | ||
| $this->fail('Pre-condition: no presentation with a media upload found in fixtures'); | ||
| } | ||
|
|
||
| /** | ||
| * @return ProcessScheduleEntityLifeCycleEvent[] | ||
| */ | ||
| private function jobsFor(string $entity_type): array | ||
| { | ||
| return Queue::pushed(ProcessScheduleEntityLifeCycleEvent::class, function ($job) use ($entity_type) { | ||
| return $job->entity_type === $entity_type; | ||
| })->all(); | ||
| } | ||
|
|
||
| public function testUpdateMediaUploadDispatchesLifeCycleEventWithSummitId(): void | ||
| { | ||
| $media_upload = $this->getMediaUpload(); | ||
| $summit_id = $media_upload->getPresentation()->getSummitId(); | ||
| $this->assertGreaterThan(0, $summit_id, 'Pre-condition: presentation must belong to a summit'); | ||
|
|
||
| Queue::fake(); | ||
|
|
||
| $media_upload->setName('Updated Media Upload Name'); | ||
| self::$em->persist($media_upload); | ||
| self::$em->flush(); | ||
|
|
||
| $jobs = $this->jobsFor('PresentationMediaUpload'); | ||
| $this->assertCount(1, $jobs, 'Expected 1 ProcessScheduleEntityLifeCycleEvent for PresentationMediaUpload update'); | ||
| $this->assertSame($summit_id, $jobs[0]->summit_id, 'Dispatched summit_id must be the presentation summit id, not 0'); | ||
| } | ||
|
|
||
| public function testInsertMediaUploadDispatchesLifeCycleEventWithSummitId(): void | ||
| { | ||
| $presentation = self::$presentations[0]; | ||
| $summit_id = $presentation->getSummitId(); | ||
| $this->assertGreaterThan(0, $summit_id, 'Pre-condition: presentation must belong to a summit'); | ||
|
|
||
| Queue::fake(); | ||
|
|
||
| $media_upload = new PresentationMediaUpload(); | ||
| $media_upload->setName('New Media Upload'); | ||
| $media_upload->setDescription('New Media Upload Description'); | ||
| $media_upload->setFilename('new_media_upload.png'); | ||
| $media_upload->setMediaUploadType(self::$media_uploads_types[0]); | ||
| $presentation->addMediaUpload($media_upload); | ||
| self::$em->persist($media_upload); | ||
| self::$em->flush(); | ||
|
|
||
| $jobs = $this->jobsFor('PresentationMediaUpload'); | ||
| $this->assertCount(1, $jobs, 'Expected 1 ProcessScheduleEntityLifeCycleEvent for PresentationMediaUpload insert'); | ||
| $this->assertSame($summit_id, $jobs[0]->summit_id, 'Dispatched summit_id must be the presentation summit id, not 0'); | ||
| } | ||
|
|
||
| /** | ||
| * Characterization test for the deleting() (PreRemove) path: the production | ||
| * delete flow (Presentation::removeMediaUpload() -> unsetPresentation(), | ||
| * relying on the materials collection's orphanRemoval to schedule the actual | ||
| * Doctrine delete) nulls the "presentation" association *before* flush() | ||
| * triggers PreRemove. So getSummitId() legitimately falls into its | ||
| * defensive catch and returns 0 here - same accepted degraded case already | ||
| * called out for getPresentationId(), and the same shape as SummitOwned's | ||
| * former_summit_id gap for entities whose owning reference is cleared ahead | ||
| * of removal. This is not a regression: the important behavior is that the | ||
| * lifecycle event still dispatches without throwing (see | ||
| * PresentationMaterial::getSummitId() catching \Throwable, not just | ||
| * \Exception, to survive exactly this null-presentation case). | ||
| */ | ||
| public function testDeleteMediaUploadDispatchesLifeCycleEventWithoutError(): void | ||
| { | ||
| $media_upload = $this->getMediaUpload(); | ||
| $presentation = $media_upload->getPresentation(); | ||
| $this->assertGreaterThan(0, $presentation->getSummitId(), 'Pre-condition: presentation must belong to a summit'); | ||
|
|
||
| Queue::fake(); | ||
|
|
||
| $presentation->removeMediaUpload($media_upload); | ||
| self::$em->flush(); | ||
|
|
||
| $jobs = $this->jobsFor('PresentationMediaUpload'); | ||
| $this->assertCount(1, $jobs, 'Expected 1 ProcessScheduleEntityLifeCycleEvent for PresentationMediaUpload delete'); | ||
| $this->assertSame(0, $jobs[0]->summit_id, 'summit_id is 0 here because unsetPresentation() runs before PreRemove - accepted degraded case, not a regression'); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.