Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fahreddinozcan committed Jul 10, 2024
1 parent b13ab1c commit 9383c16
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions tests/test_read_your_writes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

from upstash_redis import Redis

def test_set(redis: Redis):
# key = "mykey"
# value = "myvalue"
# ex_seconds = 10
#
# result = redis.set(key, value, ex=ex_seconds)
# print('heyy!!!!')
# assert result is True
# assert redis.get(key) == value
# assert redis.ttl(key) == ex_seconds
print("LETS GO")
def test_should_update_sync_token_on_basic_request(redis: Redis):
redis = Redis.from_env(read_your_writes=True)

initial_token = redis._upstash_sync_token
Expand All @@ -21,8 +11,48 @@ def test_set(redis: Redis):

updated_token = redis._upstash_sync_token

redis.get("key")
assert initial_token != updated_token

def test_should_update_sync_token_on_pipeline(redis: Redis):
redis = Redis.from_env()

initial_token = redis._upstash_sync_token

pipeline = redis.pipeline()

pipeline.set("key", "value")
pipeline.set("key2", "value2")

pipeline.exec()

updated_token = redis._upstash_sync_token

assert initial_token != updated_token

def test_updates_after_successful_lua_script_call(redis):
s = """
redis.call('SET', 'mykey', 'myvalue')
return 1
"""
initial_sync = redis._upstash_sync_token
redis.eval(
s, keys=[], args=[]
)

updated_sync = redis._upstash_sync_token
assert updated_sync != initial_sync

def test_should_not_update_sync_state_with_opt_out_ryw():
redis = Redis.from_env(read_your_writes=False)
initial_sync = redis._upstash_sync_token
redis.set("key", "value")
updated_sync = redis._upstash_sync_token
assert updated_sync == initial_sync

def test_should_update_sync_state_with_default_behavior():
redis = Redis.from_env()
initial_sync = redis._upstash_sync_token
redis.set("key", "value")
updated_sync = redis._upstash_sync_token
assert updated_sync != initial_sync

final_token = redis._upstash_sync_token
print(f"'{initial_token}' - '{updated_token}' - '{final_token}'")
assert initial_token != updated_token

0 comments on commit 9383c16

Please sign in to comment.