KAFKA-8746: Kibosh must handle an empty JSON string from Trogdor (#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 <mumrah@gmail.com>, Stanislav Kozlovski <stanislav_kozlovski@outlook.com>
This commit is contained in:
Colin Patrick McCabe 2019-11-15 15:13:32 -08:00 committed by GitHub
parent 464b6ed034
commit 7f49674439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 9 deletions

View File

@ -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

View File

@ -133,9 +133,12 @@ class KiboshService(Service):
: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):

View File

@ -70,12 +70,16 @@ class KiboshTest(Test):
[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.")

View File

@ -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