Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
refactor: python normal test
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Jul 15, 2024
1 parent f34c6ac commit a61e450
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ cmd/config.yaml
/client
log.ttrace
build/

# python cache files
test/__pycache__
6 changes: 3 additions & 3 deletions test/normal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_ping_ok():
def test_new_set_ok():
#* Creating some random sets.
for i in range(10):
set_names.append(utils.get_random_string(i+2))
set_names.append(utils.get_random_string_name(i+2))

query = f"SET {set_names[i]}"
response = utils.make_query(query, sock)
Expand All @@ -52,7 +52,7 @@ def test_new_sub_set_ok():
#* Creating some random sub sets.
for s in set_names:
for i in range(7):
sub_set_names.append(utils.get_random_string(i+2))
sub_set_names.append(utils.get_random_string_name(i+2))

query = f"SSET {s} {sub_set_names[i]}"
response = utils.make_query(query, sock)
Expand All @@ -67,7 +67,7 @@ def test_push_element_ok():
for s in set_names:
for i in range(7):
for _ in range(1_000):
element_value = utils.get_random_string(i+8)
element_value = utils.get_random_string_name(i+8)
elements_value.append(element_value)

query = f"PUSH {s} {sub_set_names[i]} {element_value} {int(time.mktime(time.gmtime()))}"
Expand Down
5 changes: 3 additions & 2 deletions test/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import random
import string
import socket

def get_random_string(length):
def get_random_string_name(length: int) -> str:
return ''.join(random.choice(string.ascii_lowercase) for i in range(length))

def make_query(query, sock):
def make_query(query: str, sock: socket.socket) -> str:
sock.sendall(query.encode())
return sock.recv(1024).decode()

0 comments on commit a61e450

Please sign in to comment.