Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sd416 committed Sep 18, 2024
1 parent b5ab3a9 commit 5343b31
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions test_log_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from log_generator import (
generate_log_line, write_logs, write_logs_random_rate,
write_logs_random_segments, main, generate_random_user_agent,
generate_ip_address, Metrics, CONFIG
generate_ip_address, Metrics
)

# Test configuration
test_config = {
'duration_normal': 5,
'duration_peak': 2,
'rate_normal_min': 0.1, # Increased rates
'rate_normal_min': 0.1, # Increased rates to ensure logs are written
'rate_normal_max': 0.5,
'rate_peak': 1.0,
'log_line_size': 100,
Expand All @@ -24,7 +24,7 @@
'log_file_path': 'test_logs.txt',
'log_rotation_enabled': False,
'log_rotation_size': 1,
'http_format_logs': False,
'http_format_logs': True, # Set to True to match default CONFIG
'stop_after_seconds': 10,
'custom_app_names': ['TestApp1', 'TestApp2'],
'custom_log_format': "${timestamp} ${log_level} ${message}"
Expand All @@ -33,8 +33,7 @@
def test_generate_log_line():
log_line = generate_log_line(
http_format_logs=test_config['http_format_logs'],
custom_app_names=test_config['custom_app_names'],
custom_log_format=test_config['custom_log_format']
custom_app_names=test_config['custom_app_names']
)
assert isinstance(log_line, str)
assert len(log_line) > 0
Expand All @@ -61,7 +60,6 @@ def test_write_logs():
test_config['rate_normal_min'], test_config['duration_normal'],
log_file, http_format_logs=test_config['http_format_logs'],
custom_app_names=test_config['custom_app_names'],
custom_log_format=test_config['custom_log_format'],
metrics=metrics_instance
)
assert os.path.getsize(log_file_path) > 0
Expand All @@ -76,7 +74,6 @@ def test_write_logs_random_rate():
test_config['duration_peak'], test_config['rate_normal_min'],
test_config['rate_normal_max'], log_file, http_format_logs=test_config['http_format_logs'],
custom_app_names=test_config['custom_app_names'],
custom_log_format=test_config['custom_log_format'],
metrics=metrics_instance
)
assert os.path.getsize(log_file_path) > 0
Expand All @@ -92,7 +89,6 @@ def test_write_logs_random_segments():
test_config['rate_normal_max'], test_config['base_exit_probability'],
log_file, http_format_logs=test_config['http_format_logs'],
custom_app_names=test_config['custom_app_names'],
custom_log_format=test_config['custom_log_format'],
metrics=metrics_instance
)
assert os.path.getsize(log_file_path) > 0
Expand Down Expand Up @@ -128,8 +124,8 @@ def test_exit_early():
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'],
test_config['custom_log_format'],
log_file, http_format_logs=test_config['http_format_logs'],
custom_app_names=test_config['custom_app_names'],
metrics=metrics_instance
)
assert os.path.getsize(log_file_path) == 0
Expand Down

0 comments on commit 5343b31

Please sign in to comment.