From 42985b00eaa3c74c55aa1e1aee2a9c077c6ac58a Mon Sep 17 00:00:00 2001 From: Harkrishn Patro Date: Tue, 25 Jul 2023 16:43:31 -0700 Subject: [PATCH] Test coverage for incr/decr operation on robj encoding type optimization (#12435) Additional test coverage for incr/decr operation. integer number could be present in raw encoding format due to operation like append. A incr/decr operation following it optimize the string to int encoding format. --- tests/unit/type/incr.tcl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unit/type/incr.tcl b/tests/unit/type/incr.tcl index c09f2e8b2..2319b2ce3 100644 --- a/tests/unit/type/incr.tcl +++ b/tests/unit/type/incr.tcl @@ -182,4 +182,33 @@ start_server {tags {"incr"}} { r incrbyfloat foo [expr double(-1)/41] r get foo } {0} + + foreach cmd {"incr" "decr" "incrby" "decrby"} { + test "$cmd operation should update encoding from raw to int" { + set res {} + set expected {1 12} + if {[string match {*incr*} $cmd]} { + lappend expected 13 + } else { + lappend expected 11 + } + + r set foo 1 + assert_encoding "int" foo + lappend res [r get foo] + + r append foo 2 + assert_encoding "raw" foo + lappend res [r get foo] + + if {[string match {*by*} $cmd]} { + r $cmd foo 1 + } else { + r $cmd foo + } + assert_encoding "int" foo + lappend res [r get foo] + assert_equal $res $expected + } + } }