The broker's rugnux live status carries expected_collection_s = images x image time (DiffractionExperiment::GetImageTime, summation included), set at START. The frontend's timeline uses it as the expected end until a frame rate is measured, and as the axis floor while collecting, so the axis no longer starts at 10 s and rescales as images arrive. An older broker without the field keeps the 10 s floor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXc1zD1yxHqaR1DGdCTHL4
63 lines
2.2 KiB
C++
63 lines
2.2 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "../receiver/RugnuxLiveStatus.h"
|
|
#include "../image_puller/TestImagePuller.h"
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
TEST_CASE("RugnuxLiveStatus_TimesFromFirstImage", "[RugnuxLive]") {
|
|
// 11 images at 100 Hz, the first 3 s after START, reported out of order as several forward threads do
|
|
const auto start = std::chrono::steady_clock::now() - 10s;
|
|
const auto first = start + 3s;
|
|
|
|
RugnuxLiveStatus status;
|
|
status.Start(11, 0.11, start);
|
|
for (int i: {1, 0, 2, 3, 4, 5, 6, 7, 8, 10, 9})
|
|
status.ImageReceived(first + i * 10ms);
|
|
|
|
auto s = status.Get();
|
|
CHECK(s.expected_collection_s.value() == Catch::Approx(0.11));
|
|
REQUIRE(s.images_received == 11);
|
|
REQUIRE(s.start_to_first_image_s.value() == Catch::Approx(3.0));
|
|
CHECK(!s.last_image_s);
|
|
// "now" is 10 s after START, 7 s after the first image
|
|
CHECK(s.elapsed_s == Catch::Approx(7.0).margin(0.5));
|
|
|
|
REQUIRE(status.LastImage() == first + 100ms);
|
|
s = status.Get();
|
|
REQUIRE(s.last_image_s.value() == Catch::Approx(0.1));
|
|
CHECK((s.images_received - 1) / s.last_image_s.value() == Catch::Approx(100.0));
|
|
}
|
|
|
|
TEST_CASE("RugnuxLiveStatus_BeforeFirstImage", "[RugnuxLive]") {
|
|
RugnuxLiveStatus status;
|
|
status.Start(10, std::nullopt, std::chrono::steady_clock::now() - 2s);
|
|
status.Step("waiting");
|
|
|
|
const auto s = status.Get();
|
|
CHECK(!s.start_to_first_image_s);
|
|
CHECK(!s.expected_collection_s);
|
|
CHECK(s.elapsed_s == 0.0);
|
|
REQUIRE(s.steps.size() == 1);
|
|
CHECK(s.steps[0].started_s <= 0.0);
|
|
CHECK(!status.LastImage());
|
|
}
|
|
|
|
TEST_CASE("TestImagePuller_SetsReceiveTime", "[RugnuxLive]") {
|
|
TestImagePuller puller;
|
|
const auto before = std::chrono::steady_clock::now();
|
|
puller.Put(ImagePullerOutput{});
|
|
const auto given = before - 5s;
|
|
puller.Put(ImagePullerOutput{.received = given});
|
|
|
|
auto out = puller.PollImage();
|
|
REQUIRE(out);
|
|
CHECK(out->received >= before);
|
|
out = puller.PollImage();
|
|
REQUIRE(out);
|
|
CHECK(out->received == given);
|
|
}
|