Skip to content

Commit

Permalink
KAFKA-8746: Kibosh must handle an empty JSON string from Trogdor (apa…
Browse files Browse the repository at this point in the history
…che#7155)

When Trogdor wants to clear all the faults injected to Kibosh, it sends the empty JSON object {}. However, Kibosh expects {"faults":[]} instead.  Kibosh should handle the empty JSON object, since that's consistent with how Trogdor handles empty JSON fields in general (if they're empty, they can be omitted). We should also have a test for this.

Reviewers: David Arthur <[email protected]>, Stanislav Kozlovski <[email protected]>
  • Loading branch information
cmccabe authored Nov 15, 2019
1 parent 464b6ed commit 7f49674
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ RUN curl -s "$KAFKA_MIRROR/kafka-streams-2.2.1-test.jar" -o /opt/kafka-2.2.1/lib
RUN curl -s "$KAFKA_MIRROR/kafka-streams-2.3.0-test.jar" -o /opt/kafka-2.3.0/libs/kafka-streams-2.3.0-test.jar

# The version of Kibosh to use for testing.
# If you update this, also update vagrant/base.sy
ARG KIBOSH_VERSION="d85ac3ec44be0700efe605c16289fd901cfdaa13"
# If you update this, also update vagrant/base.sh
ARG KIBOSH_VERSION="8841dd392e6fbf02986e2fb1f1ebf04df344b65a"

# Install Kibosh
RUN apt-get install fuse
Expand Down
9 changes: 6 additions & 3 deletions tests/kafkatest/services/trogdor/kibosh.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ def set_faults(self, node, specs):
:param node: The node.
:param spec: An array of FaultSpec objects describing the faults.
"""
fault_array = [spec.kibosh_message for spec in specs]
obj = { 'faults': fault_array }
obj_json = json.dumps(obj)
if len(specs) == 0:
obj_json = "{}"
else:
fault_array = [spec.kibosh_message for spec in specs]
obj = { 'faults': fault_array }
obj_json = json.dumps(obj)
node.account.create_file(self.control_path, obj_json)

def get_fault_json(self, node):
Expand Down
10 changes: 7 additions & 3 deletions tests/kafkatest/tests/tools/kibosh_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ def test_kibosh_service(self):
[self.nodes[0].name], KiboshTest.TARGET, "/foo", 12)
node = self.nodes[0]

def check(self, node):
def check(self, node, expected_json):
fault_json = self.kibosh.get_fault_json(node)
expected_json = json.dumps({"faults": [spec.kibosh_message]})
self.logger.info("Read back: [%s]. Expected: [%s]." % (fault_json, expected_json))
return fault_json == expected_json

wait_until(lambda: check(self, node, '{"faults":[]}'),
timeout_sec=10, backoff_sec=.2, err_msg="Failed to read back initial empty fault array.")
self.kibosh.set_faults(node, [spec])
wait_until(lambda: check(self, node),
wait_until(lambda: check(self, node, json.dumps({"faults": [spec.kibosh_message]})),
timeout_sec=10, backoff_sec=.2, err_msg="Failed to read back fault array.")
self.kibosh.set_faults(node, [])
wait_until(lambda: check(self, node, "{}"),
timeout_sec=10, backoff_sec=.2, err_msg="Failed to read back final empty fault array.")
2 changes: 1 addition & 1 deletion vagrant/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -ex

# The version of Kibosh to use for testing.
# If you update this, also update tests/docker/Dockerfile
export KIBOSH_VERSION=d85ac3ec44be0700efe605c16289fd901cfdaa13
export KIBOSH_VERSION=8841dd392e6fbf02986e2fb1f1ebf04df344b65a

path_to_jdk_cache() {
jdk_version=$1
Expand Down

0 comments on commit 7f49674

Please sign in to comment.