Skip to content

Commit cd64017

Browse files
reubenmillerdidier-wenzek
authored andcommitted
refactor tedge flows tests which use journactl
Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
1 parent e4d13e1 commit cd64017

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

tests/RobotFramework/tests/tedge_flows/flows/journalctl-cursor.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
[input.process]
2-
command = "sudo journalctl --no-pager --cursor-file=/tmp/tedge-agent-cursor --unit tedge-agent"
2+
# Each interval, get the next 5 log messages for a given service
3+
# Use a cursor-file (built-in journalctl functionality) to remember the last
4+
# log entry processed.
5+
#
6+
# The output is piped to grep to filter out the "No entries" output from journalctl,
7+
# and then finally piped to cat to avoid exiting with a non-zero exit code.
8+
command = """sh -c "sudo journalctl --no-pager --cursor-file=/tmp/tedge-agent-cursor --unit tedge-agent -n 5 -b | grep -v '^-- No entries --$' | cat""""
39
interval = "1s"
410

511
[[steps]]

tests/RobotFramework/tests/tedge_flows/tedge_flows.robot

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,17 @@ Running tedge-flows
9797

9898
Consuming messages from a process stdout
9999
# Assuming the flow journalctl-follow.toml has been properly installed
100-
Execute Command (sleep 1; systemctl restart tedge-agent)&
101-
Execute Command tedge mqtt sub log/journalctl-follow --duration 2s | grep 'INFO Runtime: Running'
100+
${test_start} Get Unix Timestamp
101+
Restart Service tedge-agent
102+
${messages} Should Have MQTT Messages topic=log/journalctl-follow minimum=1 date_from=${test_start}
103+
Should Not Be Empty ${messages[0]} msg=Output should not be empty lines
102104

103105
Consuming messages from a process stdout, periodically
104106
# Assuming the flow journalctl-cursor.toml has been properly installed
105-
Execute Command (sleep 1; systemctl restart tedge-agent)&
106-
Execute Command tedge mqtt sub log/journalctl-cursor --duration 2s | grep 'INFO Runtime: Running'
107-
Execute Command tedge mqtt sub log/journalctl-cursor --duration 1s | grep 'No entries'
107+
${test_start} Get Unix Timestamp
108+
Restart Service tedge-agent
109+
${messages} Should Have MQTT Messages topic=log/journalctl-cursor minimum=10 date_from=${test_start}
110+
Should Not Be Empty ${messages[0]} msg=Output should not be empty lines
108111

109112
Consuming messages from the tail of file
110113
# Assuming the flow tail-named-pipe.toml has been properly installed
@@ -118,7 +121,8 @@ Consuming messages from a file, periodically
118121
Execute Command echo world >/tmp/file.input
119122
Execute Command tedge mqtt sub test/file/input --duration 1s | grep world
120123
Execute Command rm /tmp/file.input
121-
Execute Command tedge mqtt sub test/file/input --duration 1s | grep 'Error in /etc/tedge/flows/read-file-periodically.toml'
124+
Execute Command
125+
... tedge mqtt sub test/file/input --duration 1s | grep 'Error in /etc/tedge/flows/read-file-periodically.toml'
122126
Execute Command echo 'hello world' >/tmp/file.input
123127
Execute Command tedge mqtt sub test/file/input --duration 1s | grep 'hello world'
124128

0 commit comments

Comments
 (0)