[PATCH] ldb: Use deterministic order of dict for tests

Lukas Slebodnik lslebodn at fedoraproject.org
Fri Jan 18 19:48:46 UTC 2019


ehlo,

Unit test failed for me in fedora on s390x
https://kojipkgs.fedoraproject.org//work/tasks/6615/32106615/build.log
https://kojipkgs.fedoraproject.org//work/tasks/7969/32107969/build.log

But there is also a reasonable reproducer on x86_64

sh$ cat > reproducer.py <<EOF
import ldb
msg = ldb.Message()
msg.dn = ldb.Dn(ldb.Ldb(), "dc=foo29")
msg["dc"] = b"foo"
print(repr(msg))
EOF

sh$ PYTHONHASHSEED=2 python2 reproducer.py
Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})

sh$ PYTHONHASHSEED=1 python2 reproducer.py
Message({'dn': Dn('dc=foo29'), 'dc': MessageElement(['foo'])})

sh$  for i in {1..10}; do PYTHONHASHSEED=random python2
reproducer.py; done
Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})
Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})
Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})
Message({'dn': Dn('dc=foo29'), 'dc': MessageElement(['foo'])})
Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})
Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})
Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})
Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})
Message({'dn': Dn('dc=foo29'), 'dc': MessageElement(['foo'])})
Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})

I was thinking about fixing it in pyldb.c but IMHO it does not worth
to spend time with fixing it in C in case of trivial workaround when
executing tests.

LS
-------------- next part --------------
From b34b0f3459523a93da37e881bc2bb59e5274cff8 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at fedoraproject.org>
Date: Fri, 18 Jan 2019 19:55:02 +0100
Subject: [PATCH] ldb: Use deterministic order of dict for tests

Test failed on s390x but there is a simple reproducer for any
architecture

    for i in {1..30}; do
        PYTHONHASHSEED=random \
        python2 -c 'import ldb; msg = ldb.Message(); msg.dn = ldb.Dn(ldb.Ldb(), "dc=foo29"); msg["dc"] = b"foo"; print(repr(msg)) '
    done

  ======================================================================
  FAIL: test_repr (__main__.LdbMsgTests)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "tests/python/api.py", line 2322, in test_repr
      "Message({'dn': Dn('dc=foo29'), 'dc': MessageElement(['foo'])})")
  AssertionError: "Message({'dc': MessageElement(['foo']), 'dn': Dn('dc=foo29')})" != "Message({'dn': Dn('dc=foo29'), 'dc': MessageElement(['foo'])})"
  ----------------------------------------------------------------------
  Ran 1025 tests in 29.146s
  FAILED (failures=1)
---
 lib/ldb/wscript | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/ldb/wscript b/lib/ldb/wscript
index 851344733645f51186d0b568f2741ac888a52660..02307956ccca7fdec16ba9e3aafc9b56c3a9a3e0 100644
--- a/lib/ldb/wscript
+++ b/lib/ldb/wscript
@@ -559,7 +559,7 @@ def test(ctx):
     if env.HAVE_LMDB:
         pyret = samba_utils.RUN_PYTHON_TESTS(
             ['tests/python/api.py', 'tests/python/index.py'],
-            extra_env={'SELFTEST_PREFIX': test_prefix})
+            extra_env={'SELFTEST_PREFIX': test_prefix, 'PYTHONHASHSEED': '0'})
     else:
         pyret = 0
     print("Python testsuite returned %d" % pyret)
-- 
2.20.1



More information about the samba-technical mailing list