Skip to content

Commit

Permalink
Merge pull request #2126 from reubenmiller/test-improve-pid-matching-…
Browse files Browse the repository at this point in the history
…logic

tests(lock): improve pid detection logic by using more precise matches
  • Loading branch information
reubenmiller authored Aug 4, 2023
2 parents 61a4bc2 + 2e48497 commit 67511f9
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ c8y-log-plugin health status
Execute Command sudo systemctl start c8y-log-plugin.service

Sleep 5s reason=It fails without this! It needs a better way of queuing requests
${pid}= Execute Command pgrep -f "c8y[_-]log[_-]plugin" strip=True
${pid}= Execute Command pgrep -f '^/usr/bin/c8y[_-]log[_-]plugin' strip=${True}
Execute Command sudo tedge mqtt pub 'tedge/health-check/c8y-log-plugin' ''
${messages}= Should Have MQTT Messages tedge/health/c8y-log-plugin minimum=1 maximum=2
Should Contain ${messages[0]} "pid":${pid}
Expand All @@ -25,7 +25,7 @@ c8y-configuration-plugin health status
Execute Command sudo systemctl start c8y-configuration-plugin.service

Sleep 5s reason=It fails without this! It needs a better way of queuing requests
${pid}= Execute Command pgrep -f "c8y[_-]configuration[_-]plugin" strip=True
${pid}= Execute Command pgrep -f '^/usr/bin/c8y[_-]configuration[_-]plugin' strip=${True}
Execute Command sudo tedge mqtt pub 'tedge/health-check/c8y-configuration-plugin' ''
${messages}= Should Have MQTT Messages tedge/health/c8y-configuration-plugin minimum=1 maximum=2
Should Contain ${messages[0]} "pid":${pid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Start watchdog service
Sleep 10s

Check PID of c8y-configuration-plugin
${pid}= Execute Command pgrep -f 'c8y-configuration-plugin' strip=True
${pid}= Execute Command pgrep -f '^/usr/bin/c8y-configuration-plugin' strip=${True}
Set Suite Variable ${pid}

Kill the PID
Kill Process ${pid}

Recheck PID of c8y-configuration-plugin
${pid1}= Execute Command pgrep -f 'c8y-configuration-plugin' strip=True
${pid1}= Execute Command pgrep -f '^/usr/bin/c8y-configuration-plugin' strip=${True}
Set Suite Variable ${pid1}

Compare PID change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Start watchdog service
Sleep 10s

Check PID of c8y-log-plugin
${pid}= Execute Command pgrep -f c8y-log-plugin strip=True
${pid}= Execute Command pgrep -f '^/usr/bin/c8y-log-plugin' strip=${True}
Set Suite Variable ${pid}

Kill the PID
Kill Process ${pid}

Recheck PID of c8y-log-plugin
${pid1}= Execute Command pgrep -f c8y-log-plugin strip=True
${pid1}= Execute Command pgrep -f '^/usr/bin/c8y-log-plugin' strip=${True}
Set Suite Variable ${pid1}

Compare PID change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Start watchdog service
Sleep 10s

Check PID of tedge-mapper
${pid}= Execute Command pgrep -f tedge-agent strip=True
${pid}= Execute Command pgrep -f '^/usr/bin/tedge-agent' strip=${True}
Set Suite Variable ${pid}

Kill the PID
Kill Process ${pid}

Recheck PID of tedge-agent
${pid1}= Execute Command pgrep -f tedge-agent strip=True
${pid1}= Execute Command pgrep -f '^/usr/bin/tedge-agent' strip=${True}
Set Suite Variable ${pid1}

Compare PID change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Start watchdog service

Sleep 10s
Check PID of tedge-mapper-az
${pid}= Execute Command pgrep -f 'tedge-mapper az'
${pid}= Execute Command pgrep -f '^/usr/bin/tedge-mapper az' strip=${True}
Set Suite Variable ${pid}

Kill the PID
Kill Process ${pid}

Recheck PID of tedge-agent
${pid1}= Execute Command pgrep -f 'tedge-mapper az'
${pid1}= Execute Command pgrep -f '^/usr/bin/tedge-mapper az' strip=${True}
Set Suite Variable ${pid1}

Compare PID change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Start watchdog service
Sleep 10s

Check PID of tedge-mapper-collectd
${pid}= Execute Command pgrep -f 'tedge-mapper collectd'
${pid}= Execute Command pgrep -f '^/usr/bin/tedge-mapper collectd' strip=${True}
Set Suite Variable ${pid}

Kill the PID
Kill Process ${pid}

Recheck PID of tedge-mapper-collectd
${pid1}= Execute Command pgrep -f 'tedge-mapper collectd' strip=True
${pid1}= Execute Command pgrep -f '^/usr/bin/tedge-mapper collectd' strip=${True}
Set Suite Variable ${pid1}

Compare PID change
Expand All @@ -51,7 +51,7 @@ tedge-collectd-mapper health status
Execute Command sudo systemctl start tedge-mapper-collectd.service

Sleep 5s reason=It fails without this! It needs a better way of queuing requests
${pid}= Execute Command pgrep -f "tedge-mapper collectd" strip=True
${pid}= Execute Command pgrep -f '^/usr/bin/tedge-mapper collectd' strip=${True}
Execute Command sudo tedge mqtt pub 'tedge/health-check/tedge-mapper-collectd' ''
${messages}= Should Have MQTT Messages tedge/health/tedge-mapper-collectd minimum=1 maximum=2
Should Contain ${messages[0]} "pid":${pid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Start watchdog service

Sleep 10s
Check PID of tedge-mapper
${pid}= Execute Command pgrep -f 'tedge-mapper c8y' strip=True
${pid}= Execute Command pgrep -f '^/usr/bin/tedge-mapper c8y' strip=${True}
Set Suite Variable ${pid}

Kill the PID
Kill Process ${pid}

Recheck PID of tedge-mapper
${pid1}= Execute Command pgrep -f 'tedge-mapper c8y' strip=True
${pid1}= Execute Command pgrep -f '^/usr/bin/tedge-mapper c8y' strip=${True}
Set Suite Variable ${pid1}

Compare PID change
Expand Down
8 changes: 4 additions & 4 deletions tests/RobotFramework/tests/configuration/lock_file.robot
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Check lock file existence in default folder

Check PID number in lock file
[Documentation] Include the pid inside the existing lock files under /run/lock/
${pid_agent1}= Execute Command pgrep -f 'tedge-agent' strip=True
${pid_mapper1}= Execute Command pgrep -f 'tedge-mapper c8y' strip=True
${pid_agent1}= Execute Command pgrep -f '^/usr/bin/tedge-agent' strip=${True}
${pid_mapper1}= Execute Command pgrep -f '^/usr/bin/tedge-mapper c8y' strip=${True}
${pid_agent_lock1}= Execute Command cat /run/lock/tedge-agent.lock
${pid_mapper_lock1}= Execute Command cat /run/lock/tedge-mapper-c8y.lock
Should Be Equal ${pid_agent1} ${pid_agent_lock1}
Expand All @@ -30,8 +30,8 @@ Check PID number in lock file after restarting the services
... inside the existing lock files under /run/lock/
Restart Service tedge-agent
Restart Service tedge-mapper-c8y
${pid_agent2}= Execute Command pgrep -f 'tedge-agent' strip=True
${pid_mapper2}= Execute Command pgrep -f 'tedge-mapper c8y' strip=True
${pid_agent2}= Execute Command pgrep -f '^/usr/bin/tedge-agent' strip=True
${pid_mapper2}= Execute Command pgrep -f '^/usr/bin/tedge-mapper c8y' strip=${True}
${pid_agent_lock2}= Execute Command cat /run/lock/tedge-agent.lock
${pid_mapper_lock2}= Execute Command cat /run/lock/tedge-mapper-c8y.lock
Should Be Equal ${pid_agent2} ${pid_agent_lock2}
Expand Down

0 comments on commit 67511f9

Please sign in to comment.