Hi all,

I noticed that we're doing a lot of sorting in the JSON code which is not
needed except for testing. Problem is that if I remove the sorting, then
most of the tests break. I spent a fair amount of time trying to fix them
but it's getting harder and harder.

Possibly, the best way to fix it would be to rewrite the tests in some
other way but I'd like to get your feedback.

At the bottom of the e-mail is the patch that I wrote and even though I
fixed a few tests (basically applying egrep to the output of test-ovsdb.py
to filter out some stuff) but there's still others that fail. For example:

1335. ovsdb-types.at:18: testing integer enum - Python2
+++ /home/centos/ovs-perf/ovs/tests/testsuite.dir/at-groups/1335/stdout
2018-09-11 22:50:45.577339922 +0000
@@ -1,2 +1,2 @@
-{"enum":["set",[-1,4,5]],"type":"integer"}
+{"enum":["set",[4,5,-1]],"type":"integer"}

[centos@centos python]$ python test-ovsdb.py -t 10000 parse-base-type
'{"type": "integer", "enum": ["set", [-1, 4, 5]]}'
{"enum":["set",[4,5,-1]],"type":"integer"}

The test would expect the set to be ordered ([-1, 4, 5]) so it fails as I
removed the sorting.

For now I'm only focusing on Python code but this happens also in C. I want
to pull some numbers to figure out the performance hit of this sorting but
anyways it doesn't make sense to do it just for the sake of testing.

What do you folks think?
Thanks!
Daniel

diff --git a/python/ovs/db/data.py b/python/ovs/db/data.py
index 9e57595..80665ba 100644
--- a/python/ovs/db/data.py
+++ b/python/ovs/db/data.py
@@ -379,12 +379,12 @@ class Datum(object):
     def to_json(self):
         if self.type.is_map():
             return ["map", [[k.to_json(), v.to_json()]
-                            for k, v in sorted(self.values.items())]]
+                            for k, v in self.values.items()]]
         elif len(self.values) == 1:
             key = next(six.iterkeys(self.values))
             return key.to_json()
         else:
-            return ["set", [k.to_json() for k in
sorted(self.values.keys())]]
+            return ["set", [k.to_json() for k in self.values.keys()]]

     def to_string(self):
         head = tail = None
@@ -400,7 +400,7 @@ class Datum(object):
         if head:
             s.append(head)

-        for i, key in enumerate(sorted(self.values)):
+        for i, key in enumerate(self.values):
             if i:
                 s.append(", ")

@@ -499,7 +499,7 @@ class Datum(object):
                 dk = uuid_to_row(k.value, self.type.key)
                 if dk is not None:
                     s.add(dk)
-            return sorted(s)
+            return list(s)

     @staticmethod
     def from_python(type_, value, row_to_uuid):
@@ -566,13 +566,13 @@ class Datum(object):
             return ["static struct ovsdb_datum %s = { .n = 0 };"]

         s = ["static union ovsdb_atom %s_keys[%d] = {" % (name, n)]
-        for key in sorted(self.values):
+        for key in self.values:
             s += ["    { %s }," % key.cInitAtom(key)]
         s += ["};"]

         if self.type.value:
             s = ["static union ovsdb_atom %s_values[%d] = {" % (name, n)]
-            for k, v in sorted(self.values.items()):
+            for k, v in self.values.items():
                 s += ["    { %s }," % v.cInitAtom(v)]
             s += ["};"]
_______________________________________________
discuss mailing list
disc...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-discuss

Reply via email to