From 8f609b6c17a7eec030f4acdde69e2b5c4dd4778f Mon Sep 17 00:00:00 2001 From: c-blake Date: Tue, 9 Jul 2024 09:42:20 +0000 Subject: [PATCH] Fix tests to be string hash order independent (#551) --- tests/testhttpserver.nim | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/testhttpserver.nim b/tests/testhttpserver.nim index 70cca33e..4cc61a07 100644 --- a/tests/testhttpserver.nim +++ b/tests/testhttpserver.nim @@ -13,6 +13,11 @@ import stew/base10 {.used.} +# Trouble finding this if defined near its use for `data2.sorted`, etc. likely +# related to "generic sandwich" issues. If any test ever wants to `sort` a +# `seq[(string, seq[string]]` differently, they may need to re-work that test. +proc `<`(a, b: (string, seq[string])): bool = a[0] < b[0] + suite "HTTP server testing suite": teardown: checkLeaks() @@ -846,11 +851,11 @@ suite "HTTP server testing suite": for key, value in table1.items(true): data2.add((key, value)) - check: - data1 == @[("Header2", "value2"), ("Header2", "VALUE3"), - ("Header1", "value1")] - data2 == @[("Header2", @["value2", "VALUE3"]), - ("Header1", @["value1"])] + check: # .sorted to not depend upon hash(key)-order + data1.sorted == sorted(@[("Header2", "value2"), ("Header2", "VALUE3"), + ("Header1", "value1")]) + data2.sorted == sorted(@[("Header2", @["value2", "VALUE3"]), + ("Header1", @["value1"])]) table1.set("header2", "value4") check: