]> git.saurik.com Git - redis.git/commitdiff
Added a new hash fuzzy tester.
authorantirez <antirez@gmail.com>
Tue, 12 Jun 2012 13:20:16 +0000 (15:20 +0200)
committerantirez <antirez@gmail.com>
Tue, 12 Jun 2012 13:20:16 +0000 (15:20 +0200)
The new fuzzy tester also removes elements from the hash instead of just
adding random fields. This should increase the probability to find bugs
in the implementations of the hash type internal representations.

tests/unit/type/hash.tcl

index dbc1c4cc31b8c363cd45a0aff99dc630184d63f5..fa52afd167ad5e2228525f701f75917a41768ecb 100644 (file)
@@ -397,7 +397,7 @@ start_server {tags {"hash"}} {
     } {b}
 
     foreach size {10 512} {
     } {b}
 
     foreach size {10 512} {
-        test "Hash fuzzing - $size fields" {
+        test "Hash fuzzing #1 - $size fields" {
             for {set times 0} {$times < 10} {incr times} {
                 catch {unset hash}
                 array set hash {}
             for {set times 0} {$times < 10} {incr times} {
                 catch {unset hash}
                 array set hash {}
@@ -418,6 +418,43 @@ start_server {tags {"hash"}} {
                 assert_equal [array size hash] [r hlen hash]
             }
         }
                 assert_equal [array size hash] [r hlen hash]
             }
         }
+
+        test "Hash fuzzing #2 - $size fields" {
+            for {set times 0} {$times < 10} {incr times} {
+                catch {unset hash}
+                array set hash {}
+                r del hash
+
+                # Create
+                for {set j 0} {$j < $size} {incr j} {
+                    randpath {
+                        set field [randomValue]
+                        set value [randomValue]
+                        r hset hash $field $value
+                        set hash($field) $value
+                    } {
+                        set field [randomSignedInt 512]
+                        set value [randomSignedInt 512]
+                        r hset hash $field $value
+                        set hash($field) $value
+                    } {
+                        randpath {
+                            set field [randomValue]
+                        } {
+                            set field [randomSignedInt 512]
+                        }
+                        r hdel hash $field
+                        unset -nocomplain hash($field)
+                    }
+                }
+
+                # Verify
+                foreach {k v} [array get hash] {
+                    assert_equal $v [r hget hash $k]
+                }
+                assert_equal [array size hash] [r hlen hash]
+            }
+        }
     }
 
     test {Stress test the hash ziplist -> hashtable encoding conversion} {
     }
 
     test {Stress test the hash ziplist -> hashtable encoding conversion} {