-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an integration test for heartbeat
An integration test is to verify if the agent gets disconnected when did not receive heartbeat since threshold from controller. Signed-off-by: Joonyoung Shim <[email protected]>
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/tests/tier0/bluechi-heartbeat-agent-disconnected/main.fmf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
summary: Test if the agent gets disconnected when did not receive heartbeat since | ||
threshold from controller | ||
id: 9ea390ed-9ba9-4961-838b-ad44cbe9f0b1 |
43 changes: 43 additions & 0 deletions
43
tests/tests/tier0/bluechi-heartbeat-agent-disconnected/python/is_agent_disconnected.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# | ||
# Copyright Contributors to the Eclipse BlueChi project | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import time | ||
import unittest | ||
|
||
from dasbus.loop import EventLoop | ||
from dasbus.typing import Variant | ||
|
||
from bluechi.api import Agent | ||
|
||
|
||
class TestAgentIsDisconnected(unittest.TestCase): | ||
|
||
state = None | ||
timestamp = None | ||
|
||
def test_agent_is_disconnected(self): | ||
loop = EventLoop() | ||
|
||
def on_state_change(state: Variant): | ||
self.timestamp = round(time.time() * 1000000) | ||
self.state = state.get_string() | ||
loop.quit() | ||
|
||
agent = Agent() | ||
assert agent.status == "online" | ||
|
||
agent.on_status_changed(on_state_change) | ||
timestamp = agent.last_seen_timestamp | ||
|
||
loop.run() | ||
|
||
# verify that the agent is disconnected after more than | ||
# ControllerHeartbeatThreshold seconds have elapsed | ||
assert self.timestamp - timestamp > 6000000 | ||
assert self.state == "offline" | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
40 changes: 40 additions & 0 deletions
40
...s/tier0/bluechi-heartbeat-agent-disconnected/test_bluechi_heartbeat_agent_disconnected.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# | ||
# Copyright Contributors to the Eclipse BlueChi project | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import os | ||
from typing import Dict | ||
|
||
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig | ||
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine | ||
from bluechi_test.test import BluechiTest | ||
|
||
node_foo_name = "node-foo" | ||
|
||
|
||
def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]): | ||
node_foo = nodes[node_foo_name] | ||
|
||
result, output = node_foo.run_python( | ||
os.path.join("python", "is_agent_disconnected.py") | ||
) | ||
if result != 0: | ||
raise Exception(output) | ||
|
||
|
||
def test_bluechi_heartbeat_agent_disconnected( | ||
bluechi_test: BluechiTest, | ||
bluechi_ctrl_default_config: BluechiControllerConfig, | ||
bluechi_node_default_config: BluechiAgentConfig, | ||
): | ||
|
||
bluechi_ctrl_default_config.allowed_node_names = [node_foo_name] | ||
|
||
bluechi_node_default_config.node_name = node_foo_name | ||
bluechi_node_default_config.controller_heartbeat_threshold = "6000" | ||
|
||
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config) | ||
bluechi_test.add_bluechi_agent_config(bluechi_node_default_config) | ||
|
||
bluechi_test.run(exec) |