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

Commit

Permalink
test: python general test
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Jul 14, 2024
1 parent 0c90cd3 commit 7b6a16b
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 4 deletions.
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Contributing

Thank you for considering contributing to go-TimeTraceDB!
Thank you for considering contributing to TimeTrace!
Please read these guidelines before submitting a pull request or opening an issue.

## Code guidelines

We strive to maintain clean, readable, and maintainable code in go-TimeTraceDB.
We strive to maintain clean, readable, and maintainable code in TimeTrace.
Please follow these guidelines when contributing code to the project:

- Code should follow the [Effective Go](https://golang.org/doc/effective_go.html) guidelines.
Expand All @@ -24,6 +24,8 @@ The following commands are available in the Makefile:
- `make check` runs various checks on the code, including formatting and linting.
- `make test` runs the tests to ensure that all functionality is working as intended.

All golang and [python](./test/README.md) must be passed.

## Commit guidelines

Please follow these guidelines when committing changes to go-TimeTraceDB:
Expand Down Expand Up @@ -55,4 +57,4 @@ Please read it before contributing to the project.

---

Thank you for your contributions to go-TimeTraceDB!
Thank you for your contributions to TimeTrace!
2 changes: 1 addition & 1 deletion doc/TQL/TQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Time trace is using a query language called TQL. Here is documentation and speci
| CNTS * | returns count of sets | |
| CNTSS * | returns count of subsets | set-name |
| CNTE * | returns count of elements | set-name - subset-name |
| CLN * | cleans all database sets (the sets themselves) | set-name - subset-name |
| CLN * | cleans all database sets (the sets themselves) | |
| CLNS * | cleans all sub-sets of a set | set-name |
| CLNSS * | cleans all elements of a subset | set-name - subset-name |
| DRPS * | drops a set | set-name |
Expand Down
Empty file removed test/.keep
Empty file.
12 changes: 12 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Tests

This directory contains a set of python scripts for testing time-trace database. Each change or pull request must pass this test otherwise it won't be merged.

## Checklist

Here is a list of different tests which must be added here and their status:

| Test | Status |
| -------- | ------- |
| Normal test ||
| Concurrent test | ⚒️ |
148 changes: 148 additions & 0 deletions test/normal_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import socket
import time
import utils
import random

#! GET method is not tested here now.
# TODO: writing test for method GET.
# TODO: adding test bad cases such as invalid set/subset name.

st = time.time()

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server_address = ('localhost', 7070) # You can change port and host for testing.
sock.connect(server_address)

#? TQL command to connect to the server.
query = "CON root super_secret_password" #! Considers you config is default.
response = utils.make_query(query, sock)

assert response == "OK"
print(f"Received response: {response}, Connection test Passed!")

#? Ping database.
assert utils.make_query("PING", sock) == "PONG"
print(f"Received response: {response}, We are connected!")

#* Creating some random sets.
set_names = []
for i in range(10):
set_names.append(utils.get_random_string(i+2))
query = f"SET {set_names[i]}"

response = utils.make_query(query, sock)
assert response == "OK"

print(f"Received response: {response}, Created {len(set_names)} sets successfully.")

#* Creating some random sub sets.
sub_set_names = []
for s in set_names:
for i in range(7):
sub_set_names.append(utils.get_random_string(i+2))

query = f"SSET {s} {sub_set_names[i]}"
response = utils.make_query(query, sock)
assert response == "OK"

print(f"Received response: {response}, Created {len(sub_set_names)} sub sets successfully.")

#* Pushing some random elements.
set_index = 0
elements_value = []
for s in set_names:
for i in range(7):
for _ in range(1_000):
element_value = utils.get_random_string(i+8)
elements_value.append(element_value)

query = f"PUSH {s} {sub_set_names[i]} {element_value} {int(time.mktime(time.gmtime()))}"

response = utils.make_query(query, sock)
assert response == "OK"

set_index += 7

print(f"Received response: {response}, Created {len(elements_value)} elements pushed successfully.")

#* Test count
response = utils.make_query("CNTS", sock)
assert response == str(len(set_names))
print(f"Received response: {response}, Sets number counted successfully.")

sub_sets_count = 0
for s in set_names:
query = f"CNTSS {s}"
response = utils.make_query(query, sock)
sub_sets_count += int(response)

assert sub_sets_count == len(sub_set_names)
print(f"Received response: {sub_sets_count}, SubSets number counted successfully.")

set_index = 0
elements_count = 0
for s in set_names:
for i in range(7):
query = f"CNTE {s} {sub_set_names[i]}"

response = utils.make_query(query, sock)
elements_count += int(response)

set_index += 7

assert elements_count == len(elements_value)
print(f"Received response: {elements_count}, Elements number counted successfully.")

#* Test clean sub sets
set_index = 0
for s in set_names:
for i in range(7):
query = f"CLNSS {s} {sub_set_names[i]}"

response = utils.make_query(query, sock)
assert response == "OK"

set_index += 7

print(f"Received response: {response}, All Subset elements cleaned successfully.")


#* Test drop subsets
set_index = 0
for s in set_names:
for i in range(7):
query = f"DRPSS {s} {sub_set_names[i]}"

response = utils.make_query(query, sock)
assert response == "OK"

set_index += 7

print(f"Received response: {response}, All Subset dropped successfully.")

#* Test clean sets
for s in set_names:
query = f"CLNS {s}"

response = utils.make_query(query, sock)
assert response == "OK"

print(f"Received response: {response}, All Subsets cleaned successfully.")

#* Test drop sets
for s in set_names:
query = f"DRPS {s}"

response = utils.make_query(query, sock)
assert response == "OK"

print(f"Received response: {response}, All Sets dropped successfully.")

#* Clean all sets.
response = utils.make_query("CLN", sock)
assert response == "OK"
print(f"Received response: {response}, All Sets cleaned successfully.")

sock.close()
print('All test successfully passed in:', time.time() - st, 'seconds')
9 changes: 9 additions & 0 deletions test/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import random
import string

def get_random_string(length):
return ''.join(random.choice(string.ascii_lowercase) for i in range(length))

def make_query(query, sock):
sock.sendall(query.encode())
return sock.recv(1024).decode()

0 comments on commit 7b6a16b

Please sign in to comment.