fppt / jedis-mock

A simple redis java mock for unit testing
Apache License 2.0
161 stars 58 forks source link

Redis Mock sending record in the incorrect order #375

Open asiaantczak opened 9 months ago

asiaantczak commented 9 months ago

Hi,

Thank you for such a valuable project. I was looking for a redis mock to use in my unit tests and this one fits perfectly. However what I get from the mock does not completely match what test expects. All the data are correct except the order.

My Redis Mock

val redisServer = RedisServer(props.port)
 @PostConstruct
    fun postConstruct() {
        redisServer.start()
    }

My Redis code implementation uses Reactive String Redis Template

My test expects a list of

val DUMMY_REDIS_HASHES: RedisHashes =
    listOf(
        "userId", DUMMY_USER_ID.toString(),
        "attempts", "0",
        "validUntil", NOW.toString(),
        "passcode-$DUMMY_PASSCODE_NUMBER", DUMMY_PASSCODE_NUMBER
    )

[[pool-4-thread-1] DEBUG com.github.fppt.jedismock.server.Response - Received command [evalsha] sending reply [*10$15passcode-654321$6654321$15passcode-123456$6123456$10validUntil$202007-12-03T10:15:30Z$8attempts$10$6userId$368a2c1033-a8b3-48c4-8698-7fef9f6ca3de]

Expected :["userId", "8a2c1033-a8b3-48c4-8698-7fef9f6ca3de", "attempts", "0", "validUntil", "2007-12-03T10:15:30Z", "passcode-123456", "123456"] Actual :["passcode-123456", "123456", "validUntil", "2007-12-03T10:15:30Z", "attempts", "0", "userId", "8a2c1033-a8b3-48c4-8698-7fef9f6ca3de"]

The same test works fine with Test Containers.

Is order not guaranteed?

Thank you,

inponomarev commented 9 months ago

Hello! Thank you for your report. Could you please give me more context:

  1. What Redis client (Jedis/Lettuce/Redisson) are you using? I cannot figure out where RedisHashes class comes from.
  2. Could you give a working code snippet that demonstrates the error (different order).

We're trying to keep JedisMock's behaviour as close to "real Redis" as we can, so of course if can be fixed, we'll fix it.