Skip to content

Commit

Permalink
[integration] - made integration tests make multiple domains instead …
Browse files Browse the repository at this point in the history
…of committing to same domain
  • Loading branch information
LeonLiur committed Jul 22, 2024
1 parent cd994af commit e08cbc8
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 260 deletions.
51 changes: 34 additions & 17 deletions integration/py/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def num_channels(self) -> int:
)


class Write_Test():
class WriteTest:
_tc: TestConfig

def __init__(self, argv: List[str]):
argv_counter = 1
identifier = argv[argv_counter]
Expand Down Expand Up @@ -85,22 +85,25 @@ def __init__(self, argv: List[str]):
data_channels.append(argv[i])
argv_counter += number_of_data
channel_groups.append(
IndexWriterGroup(index_channels=index_channels, data_channels=data_channels)
IndexWriterGroup(
index_channels=index_channels, data_channels=data_channels
)
)
self._tc = TestConfig(
identifier=identifier,
num_writers=num_writers,
domains=domains,
samples_per_domain=samples_per_domain,
time_range=sy.TimeRange(sy.TimeStamp(time_range_start), sy.TimeStamp(time_range_end)),
time_range=sy.TimeRange(
sy.TimeStamp(time_range_start), sy.TimeStamp(time_range_end)
),
channels=channel_groups,
auto_commit=auto_commit,
index_persist_interval=index_persist_interval,
expected_error=expected_error,
writer_mode=writer_mode,
)


def test_with_timing(self):
start = sy.TimeStamp.now()
error_assertion_passed = False
Expand All @@ -109,30 +112,34 @@ def test_with_timing(self):
self.test()
except Exception as e:
actual_error = str(e)
if self._tc.expected_error != "no_error" and self._tc.expected_error in str(e):
if (
self._tc.expected_error != "no_error"
and self._tc.expected_error in str(e)
):
error_assertion_passed = True
else:
raise(e)
raise (e)
else:
actual_error = "no_error"
if self._tc.expected_error == "no_error":
error_assertion_passed = True
end = sy.TimeStamp.now()

err_assertion = f'''
err_assertion = f"""
Expected error: {self._tc.expected_error}; Actual error: {actual_error}\n{"PASS!!" if error_assertion_passed else "FAIL!!"}
'''
"""

s = self.generate_test_report(start.span(end), err_assertion)

with open(FILE_NAME, "a") as f:
f.write(s)


def generate_test_report(self, time: sy.TimeSpan, err_assertion: str) -> str:
samples = self._tc.num_channels() * self._tc.samples_per_domain * self._tc.domains
samples = (
self._tc.num_channels() * self._tc.samples_per_domain * self._tc.domains
)
samples_per_second = samples / (float(time) / float(sy.TimeSpan.SECOND))
s = f'''
s = f"""
-- Python Write ({self._tc.identifier}) --
Samples written: {samples:,.0f}
Time taken: {time}
Expand All @@ -147,7 +154,7 @@ def generate_test_report(self, time: sy.TimeSpan, err_assertion: str) -> str:
\tWriter mode: {sy.WriterMode(self._tc.writer_mode).name}
{err_assertion}
'''
"""

return s

Expand All @@ -173,8 +180,9 @@ def test(self):
ts_hwm + time_span_per_domain,
self._tc.samples_per_domain,
dtype="int64",
)
)
data = np.sin(0.0000000001 * timestamps)
ts_hwm += time_span_per_domain + 1
for i, writer in enumerate(writers):
data_dict = {}
for index_channel in self._tc.channels[i].index_channels:
Expand All @@ -187,15 +195,24 @@ def test(self):
if not self._tc.auto_commit:
assert writer.commit()

ts_hwm += time_span_per_domain + 1
writers[i] = client.open_writer(
start=ts_hwm,
channels=self._tc.channels[i].together(),
name=f"writer{i}",
mode=self._tc.writer_mode,
enable_auto_commit=self._tc.auto_commit,
auto_index_persist_interval=self._tc.index_persist_interval,
err_on_unauthorized=False,
)
writer.close()

finally:
for writer in writers:
writer.close()


def main():
Write_Test(sys.argv).test_with_timing()
WriteTest(sys.argv).test_with_timing()


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion integration/run-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ echo "--Compiling"
(cd ../synnax && go build -tags="development" -o ../integration/bin/synnax.exe)

# Run the Go program with the provided arguments
go run . "$1"
go run . "$1" ${2:+$2}

# Capture the exit code of the Go program
exit_code=$?
Expand Down
24 changes: 0 additions & 24 deletions integration/tests/ws-d-r-mini.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,30 +150,6 @@
"expected_error": "no_error"
}
},
{
"op": "write",
"client": "ts",
"delay": 1.5,
"params": {
"channel_groups": [
{
"index_channels": [
"int1"
],
"data_channels": []
}
],
"num_writers": 1,
"domains": 1000,
"samples_per_domain": 2000,
"time_range": {
"start": 0,
"end": 1000000000000000
},
"writer_mode": 1,
"expected_error": "unauthorized"
}
},
{
"op": "delete",
"client": "py",
Expand Down
28 changes: 2 additions & 26 deletions integration/tests/ws-d-r.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
}
],
"num_writers": 3,
"domains": 10000,
"samples_per_domain": 2000,
"domains": 10,
"samples_per_domain": 2000000,
"time_range": {
"start": 0,
"end": 1000000000000000
Expand Down Expand Up @@ -150,30 +150,6 @@
"expected_error": "no_error"
}
},
{
"op": "write",
"client": "ts",
"delay": 1,
"params": {
"channel_groups": [
{
"index_channels": [
"int1"
],
"data_channels": []
}
],
"num_writers": 1,
"domains": 100000,
"samples_per_domain": 2000,
"time_range": {
"start": 0,
"end": 1000000000000000
},
"writer_mode": 1,
"expected_error": "unauthorized"
}
},
{
"op": "delete",
"client": "py",
Expand Down
Loading

0 comments on commit e08cbc8

Please sign in to comment.