Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mtconnect/pipeline/correct_timestamp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace mtconnect::pipeline {
}
}

m_state->m_timestamps.emplace(id, ts);
m_state->m_timestamps.insert_or_assign(id, ts);

return next(std::move(obs));
}
Expand Down
48 changes: 48 additions & 0 deletions test_package/correct_timestamp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,51 @@ TEST_F(ValidateTimestampTest, should_change_timestamp_if_time_is_moving_backward
ASSERT_NE(now - 1s, obs2->getTimestamp());
ASSERT_LE(now, obs2->getTimestamp());
}

TEST_F(ValidateTimestampTest, should_handle_timestamp_in_the_future)
{
makeDataItem({{"id", "a"s}, {"type", "EXECUTION"s}, {"category", "EVENT"s}});

auto filter = make_shared<CorrectTimestamp>(m_context);
m_mapper->bind(filter);
filter->bind(make_shared<DeliverObservation>(m_context));

auto now = chrono::system_clock::now();

{
auto os = observe({"a", "READY"}, now - 1s);
auto list = os->getValue<EntityList>();
ASSERT_EQ(1, list.size());

auto obs = dynamic_pointer_cast<Observation>(list.front());
ASSERT_EQ(now - 1s, obs->getTimestamp());
}

{
auto os = observe({"a", "ACTIVE"}, now + 1s);
auto list = os->getValue<EntityList>();
ASSERT_EQ(1, list.size());

auto obs = dynamic_pointer_cast<Observation>(list.front());
ASSERT_EQ(now + 1s, obs->getTimestamp());
}

{
auto os = observe({"a", "READY"}, now);
auto list = os->getValue<EntityList>();
ASSERT_EQ(1, list.size());

auto obs = dynamic_pointer_cast<Observation>(list.front());
ASSERT_LT(now, obs->getTimestamp());
ASSERT_GT(now + 10ms, obs->getTimestamp());
}

{
auto os = observe({"a", "ACTIVE"}, now + 2s);
auto list = os->getValue<EntityList>();
ASSERT_EQ(1, list.size());

auto obs = dynamic_pointer_cast<Observation>(list.front());
ASSERT_EQ(now + 2s, obs->getTimestamp());
}
}