Skip to content

Commit

Permalink
Updated script, added more tests, added stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Shriram committed Jun 27, 2024
1 parent 1ad01db commit fa3f867
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test_log_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import time
import ipaddress
import random
from log_generator import (
generate_log_line, write_logs, write_logs_random_rate,
write_logs_random_segments, main, generate_random_user_agent,
Expand Down Expand Up @@ -91,7 +92,7 @@ def test_main_no_file():
test_metrics = Metrics()

# Modify main function to accept metrics as an argument
def main_with_metrics(config, metrics):
def main_with_metrics(config, metrics_instance):
start_time = time.time()
iteration = 0

Expand All @@ -100,10 +101,10 @@ def main_with_metrics(config, metrics):
write_logs_random_rate(config['duration_peak'], config['rate_normal_max'], config['rate_peak'], None, config['http_format_logs'], config['custom_app_names'], config['custom_log_format'])

iteration += 1
print(f"Iteration {iteration} metrics: {metrics.get_stats()}")
print(f"Iteration {iteration} metrics: {metrics_instance.get_stats()}")

# Print final metrics
print(f"Final metrics: {metrics.get_stats()}")
print(f"Final metrics: {metrics_instance.get_stats()}")

main_with_metrics(test_config, test_metrics)
assert test_metrics.get_stats()['total_logs'] > 0
Expand All @@ -114,4 +115,4 @@ def test_exit_early(tmp_path):
test_config['base_exit_probability'] = 1.0 # Ensure early exit
with open(log_file_path, 'w') as log_file:
write_logs_random_segments(test_config['duration_normal'], 1, test_config['rate_normal_min'], test_config['rate_normal_max'], test_config['base_exit_probability'], log_file, test_config['http_format_logs'], test_config['custom_app_names'])
assert log_file_path.read_text().strip() == ""
assert log_file_path.read_text().strip() == ""

0 comments on commit fa3f867

Please sign in to comment.