Skip to content

Commit 240bf80

Browse files
authored
Merge pull request #546 from mtconnect/538_fix_check_timestamps
2 parents c9792cb + b91097e commit 240bf80

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/mtconnect/pipeline/correct_timestamp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace mtconnect::pipeline {
7474
}
7575
}
7676

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

7979
return next(std::move(obs));
8080
}

test_package/correct_timestamp_test.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,51 @@ TEST_F(ValidateTimestampTest, should_change_timestamp_if_time_is_moving_backward
165165
ASSERT_NE(now - 1s, obs2->getTimestamp());
166166
ASSERT_LE(now, obs2->getTimestamp());
167167
}
168+
169+
TEST_F(ValidateTimestampTest, should_handle_timestamp_in_the_future)
170+
{
171+
makeDataItem({{"id", "a"s}, {"type", "EXECUTION"s}, {"category", "EVENT"s}});
172+
173+
auto filter = make_shared<CorrectTimestamp>(m_context);
174+
m_mapper->bind(filter);
175+
filter->bind(make_shared<DeliverObservation>(m_context));
176+
177+
auto now = chrono::system_clock::now();
178+
179+
{
180+
auto os = observe({"a", "READY"}, now - 1s);
181+
auto list = os->getValue<EntityList>();
182+
ASSERT_EQ(1, list.size());
183+
184+
auto obs = dynamic_pointer_cast<Observation>(list.front());
185+
ASSERT_EQ(now - 1s, obs->getTimestamp());
186+
}
187+
188+
{
189+
auto os = observe({"a", "ACTIVE"}, now + 1s);
190+
auto list = os->getValue<EntityList>();
191+
ASSERT_EQ(1, list.size());
192+
193+
auto obs = dynamic_pointer_cast<Observation>(list.front());
194+
ASSERT_EQ(now + 1s, obs->getTimestamp());
195+
}
196+
197+
{
198+
auto os = observe({"a", "READY"}, now);
199+
auto list = os->getValue<EntityList>();
200+
ASSERT_EQ(1, list.size());
201+
202+
auto obs = dynamic_pointer_cast<Observation>(list.front());
203+
ASSERT_LT(now, obs->getTimestamp());
204+
ASSERT_GT(now + 10ms, obs->getTimestamp());
205+
}
206+
207+
{
208+
auto os = observe({"a", "ACTIVE"}, now + 2s);
209+
auto list = os->getValue<EntityList>();
210+
ASSERT_EQ(1, list.size());
211+
212+
auto obs = dynamic_pointer_cast<Observation>(list.front());
213+
ASSERT_EQ(now + 2s, obs->getTimestamp());
214+
}
215+
}

0 commit comments

Comments
 (0)