Skip to content

Commit

Permalink
Merge pull request #2478 from oat-sa/hotfix/AUT-3680/getCurrentAssess…
Browse files Browse the repository at this point in the history
…mentItemRef-on-null

Hotfix: avoid  getCurrentAssessmentAtemRef on null
  • Loading branch information
pnal authored Jun 6, 2024
2 parents 5503d60 + 82f80cb commit 836636a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 37 deletions.
75 changes: 38 additions & 37 deletions model/Service/ConcurringSessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,54 +167,55 @@ public function adjustTimers(DeliveryExecution $execution): void
);

$testSession = $this->getTestSessionService()->getTestSession($execution);
if (!$testSession || !$testSession->getCurrentAssessmentItemRef()) {
return;
}

if ($testSession->getCurrentAssessmentItemRef()) {
$duration = $testSession->getTimerDuration(
$testSession->getCurrentAssessmentItemRef()->getIdentifier(),
$testSession->getTimerTarget()
);

$this->logger->debug(
sprintf(
'Timer duration on execution %s timer adjustment = %f',
$execution->getIdentifier(),
$duration->getSeconds(true)
)
);
$duration = $testSession->getTimerDuration(
$testSession->getCurrentAssessmentItemRef()->getIdentifier(),
$testSession->getTimerTarget()
);

$ids = [
$this->logger->debug(
sprintf(
'Timer duration on execution %s timer adjustment = %f',
$execution->getIdentifier(),
$execution->getOriginalIdentifier()
];
$duration->getSeconds(true)
)
);

foreach ($ids as $executionId) {
$key = "itemDuration-{$executionId}";
$ids = [
$execution->getIdentifier(),
$execution->getOriginalIdentifier()
];

if (!$this->currentSession->hasAttribute($key)) {
continue;
}
foreach ($ids as $executionId) {
$key = "itemDuration-{$executionId}";

$oldDuration = $this->currentSession->getAttribute($key);
$this->currentSession->removeAttribute($key);
if (!$this->currentSession->hasAttribute($key)) {
continue;
}

$this->logger->debug(
sprintf(
'Timer duration on execution %s pause was %f',
$execution->getIdentifier(),
$oldDuration
)
);
$oldDuration = $this->currentSession->getAttribute($key);
$this->currentSession->removeAttribute($key);

$delta = (int) ceil($duration->getSeconds(true) - $oldDuration);
$this->logger->debug(
sprintf(
'Timer duration on execution %s pause was %f',
$execution->getIdentifier(),
$oldDuration
)
);

if ($delta > 0) {
$this->logger->debug(sprintf('Adjusting timers by %d s', $delta));
$delta = (int) ceil($duration->getSeconds(true) - $oldDuration);

$this->getTimerAdjustmentService()->increase($testSession, $delta);
if ($delta > 0) {
$this->logger->debug(sprintf('Adjusting timers by %d s', $delta));

$testSession->suspend();
$this->getTestSessionService()->persist($testSession);
}
$this->getTimerAdjustmentService()->increase($testSession, $delta);

$testSession->suspend();
$this->getTestSessionService()->persist($testSession);
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/unit/model/Service/ConcurringSessionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,28 @@ public function testPauseActiveDeliveryExecutionsForUser()

$this->subject->pauseActiveDeliveryExecutionsForUser($execution);
}

public function testAdjustTimersSkipsAdjustmentIfNoTestSessionExists(): void
{
$execution = $this->createMock(DeliveryExecution::class);
$execution
->method('getIdentifier')
->willReturn('https://example.com/execution/1');

$this->testSessionService
->expects($this->once())
->method('getTestSession')
->with($execution)
->willReturn(null);

$this->currentSession
->expects($this->never())
->method('removeAttribute');

$this->testSessionService
->expects($this->never())
->method('persist');

$this->subject->adjustTimers($execution);
}
}

0 comments on commit 836636a

Please sign in to comment.