Skip to content

Commit

Permalink
rework results structures to not overwrite data
Browse files Browse the repository at this point in the history
  • Loading branch information
hitchhooker committed May 1, 2024
1 parent b405cd6 commit b9cc5a5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
4 changes: 3 additions & 1 deletion scripts/broken_bootnodes.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/bin/bash
jq '.[] | select(.valid == false)' /tmp/bootnode_tests/results.json
RESULTS_JSON="/tmp/bootnode_tests/results.json"
jq '.[] | .[] | select(.valid == false)' "$RESULTS_JSON"

22 changes: 21 additions & 1 deletion scripts/missing_bootnodes.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
#!/bin/bash
jq '[. as $root | keys[] as $instance | $root[$instance].members | to_entries | map(select(.value | length == 0) | .key as $provider | {provider: $provider, hub: $instance})] | add | group_by(.provider) | map({(.[0].provider): map(.hub)}) | add' bootnodes.json
RESULTS_JSON="/tmp/bootnode_tests/results.json"
OUTPUT_FILE="/tmp/endpoint_tests/missing.json"

missing=$(jq '
. as $root |
to_entries |
map({
id: .key,
missing_endpoints: [
.value | to_entries |
map(select(.value.valid == false) | {
network: .key,
endpoint: .value.bootnode
})
]
}) | map(select(.missing_endpoints | length > 0))
' "$RESULTS_JSON")

echo "$missing" | jq . > "$OUTPUT_FILE"
cat "$OUTPUT_FILE"


29 changes: 20 additions & 9 deletions scripts/test_bootnodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ initialize_output() {
echo "Initialized output directory and JSON file."
}

# update_results() {
# local operator="$1"
# local data_file="$2"
# local tmp_file="${OUTPUT_FILE}.tmp"
# # update results.json with the new data
# "$JQ_BINARY" --arg operator "$operator" --slurpfile data "$data_file" '
# if .[$operator] then
# .[$operator] += $data[0]
# else
# .[$operator] = $data[0]
# end
# ' "$OUTPUT_FILE" > "$tmp_file" && mv "$tmp_file" "$OUTPUT_FILE"
# }
update_results() {
local operator="$1"
local data_file="$2"
local network="$2"
local data_file="$3"
local tmp_file="${OUTPUT_FILE}.tmp"
# update results.json with the new data
"$JQ_BINARY" --arg operator "$operator" --slurpfile data "$data_file" '
if .[$operator] then
.[$operator] += $data[0]
else
.[$operator] = $data[0]
end

"$JQ_BINARY" --arg operator "$operator" --arg network "$network" --slurpfile data "$data_file" '
.[$operator] |= (if . then . else {} end) |
.[$operator][$network] |= (if . then . + $data[0] else $data[0] end)
' "$OUTPUT_FILE" > "$tmp_file" && mv "$tmp_file" "$OUTPUT_FILE"
}

Expand Down Expand Up @@ -78,7 +89,7 @@ test_bootnode() {
local result_file="$OUTPUT_DIR/${operator}.${network}.json"
echo "{\"id\":\"$operator\", \"network\":\"$network\", \"bootnode\":\"$bootnode\", \"valid\":$valid, \"peers\":\"$peer_count\"}" > "$result_file"

update_results "$operator" "$result_file"
update_results "$operator" "$network" "$result_file"
rm "$result_file"
}

Expand Down

0 comments on commit b9cc5a5

Please sign in to comment.