@@ -32,7 +32,18 @@ def test_make_run_request(run_pipeline_operation, mocker):
32
32
targets = ["t1" , "t2" ]
33
33
pipeline_name = "my_pipeline"
34
34
command = mocker .Mock ()
35
- command .option .side_effect = ["my-storage" , annotations , "10001" , targets , "10000" ]
35
+ # Updated to handle all the option calls including time-interval-seconds
36
+ option_responses = {
37
+ "storage-backend" : "my-storage" ,
38
+ "annotations" : annotations ,
39
+ "step-outbox-size" : "10001" ,
40
+ "target" : targets ,
41
+ "time-interval-seconds" : None , # No time interval provided
42
+ "reporting-frequency" : "10000" ,
43
+ }
44
+ command .option .side_effect = lambda opt : option_responses .get (opt )
45
+ command .has_json_logging_set = False # Required for create_progress_reporter
46
+ command .is_very_verbose = False # Required for make_run_request
36
47
command .argument .return_value = [pipeline_name ]
37
48
pipeline = mocker .patch ("nodestream.project.PipelineDefinition" )
38
49
pipeline .name = pipeline_name
@@ -43,6 +54,129 @@ def test_make_run_request(run_pipeline_operation, mocker):
43
54
assert_that (result .progress_reporter .reporting_frequency , equal_to (10000 ))
44
55
45
56
57
+ def test_create_progress_reporter_with_time_interval_seconds (
58
+ run_pipeline_operation , mocker
59
+ ):
60
+ """Test that time_interval_seconds gets properly converted to float and passed to PipelineProgressReporter"""
61
+ command = mocker .Mock ()
62
+ command .option .side_effect = lambda opt : {
63
+ "metrics-interval-in-seconds" : "30.5" ,
64
+ "reporting-frequency" : "1000" ,
65
+ }.get (opt )
66
+ command .has_json_logging_set = False
67
+
68
+ # Mock PipelineProgressReporter to capture arguments
69
+ mock_progress_reporter = mocker .patch (
70
+ "nodestream.cli.operations.run_pipeline.PipelineProgressReporter"
71
+ )
72
+
73
+ _ = run_pipeline_operation .create_progress_reporter (command , "test_pipeline" )
74
+
75
+ # Verify PipelineProgressReporter was called with correct time_interval_seconds
76
+ mock_progress_reporter .assert_called_once ()
77
+ call_args = mock_progress_reporter .call_args
78
+ assert_that (call_args .kwargs ["metrics_interval_in_seconds" ], equal_to (30.5 ))
79
+ assert_that (call_args .kwargs ["reporting_frequency" ], equal_to (1000 ))
80
+
81
+
82
+ def test_create_progress_reporter_without_time_interval_seconds (
83
+ run_pipeline_operation , mocker
84
+ ):
85
+ """Test that time_interval_seconds is None when not provided"""
86
+ command = mocker .Mock ()
87
+ command .option .side_effect = lambda opt : {
88
+ "metrics-interval-in-seconds" : None ,
89
+ "reporting-frequency" : "2000" ,
90
+ }.get (opt )
91
+ command .has_json_logging_set = False
92
+
93
+ # Mock PipelineProgressReporter to capture arguments
94
+ mock_progress_reporter = mocker .patch (
95
+ "nodestream.cli.operations.run_pipeline.PipelineProgressReporter"
96
+ )
97
+
98
+ _ = run_pipeline_operation .create_progress_reporter (command , "test_pipeline" )
99
+
100
+ # Verify PipelineProgressReporter was called with None for time_interval_seconds
101
+ mock_progress_reporter .assert_called_once ()
102
+ call_args = mock_progress_reporter .call_args
103
+ assert_that (call_args .kwargs ["metrics_interval_in_seconds" ], equal_to (None ))
104
+ assert_that (call_args .kwargs ["reporting_frequency" ], equal_to (2000 ))
105
+
106
+
107
+ def test_create_progress_reporter_with_json_indicator (run_pipeline_operation , mocker ):
108
+ """Test that create_progress_reporter works correctly with JSON progress indicator"""
109
+ command = mocker .Mock ()
110
+ command .option .side_effect = lambda opt : {
111
+ "metrics-interval-in-seconds" : "15.0" ,
112
+ "reporting-frequency" : "500" ,
113
+ }.get (opt )
114
+ command .has_json_logging_set = True
115
+
116
+ # Mock PipelineProgressReporter to capture arguments
117
+ mock_progress_reporter = mocker .patch (
118
+ "nodestream.cli.operations.run_pipeline.PipelineProgressReporter"
119
+ )
120
+
121
+ _ = run_pipeline_operation .create_progress_reporter (command , "test_pipeline" )
122
+
123
+ # Verify PipelineProgressReporter was called with correct arguments
124
+ mock_progress_reporter .assert_called_once ()
125
+ call_args = mock_progress_reporter .call_args
126
+ assert_that (call_args .kwargs ["metrics_interval_in_seconds" ], equal_to (15.0 ))
127
+ assert_that (call_args .kwargs ["reporting_frequency" ], equal_to (500 ))
128
+
129
+
130
+ def test_make_run_request_with_time_interval_seconds_integration (
131
+ run_pipeline_operation , mocker
132
+ ):
133
+ """Integration test to ensure make_run_request properly handles time_interval_seconds through create_progress_reporter"""
134
+ annotations = ["annotation1" ]
135
+ targets = ["t1" ]
136
+ pipeline_name = "my_pipeline"
137
+ command = mocker .Mock ()
138
+
139
+ # Setup command.option to handle all the different option calls made by make_run_request
140
+ option_responses = {
141
+ "storage-backend" : "my-storage" ,
142
+ "annotations" : annotations ,
143
+ "step-outbox-size" : "10001" ,
144
+ "target" : targets ,
145
+ "metrics-interval-in-seconds" : "45.0" ,
146
+ "reporting-frequency" : "5000" ,
147
+ }
148
+ command .option .side_effect = lambda opt : option_responses .get (opt )
149
+ command .has_json_logging_set = False
150
+ command .is_very_verbose = False
151
+ command .argument .return_value = [pipeline_name ]
152
+
153
+ pipeline = mocker .Mock ()
154
+ pipeline .name = pipeline_name
155
+ pipeline .configuration = PipelineConfiguration ()
156
+
157
+ # Mock the project's get_object_storage_by_name method
158
+ run_pipeline_operation .project .get_object_storage_by_name .return_value = None
159
+ run_pipeline_operation .project .get_target_by_name .return_value = None
160
+
161
+ # Mock PipelineProgressReporter to capture its arguments
162
+ mock_progress_reporter = mocker .patch (
163
+ "nodestream.cli.operations.run_pipeline.PipelineProgressReporter"
164
+ )
165
+
166
+ result = run_pipeline_operation .make_run_request (command , pipeline )
167
+
168
+ # Verify the progress reporter was created with correct time_interval_seconds
169
+ mock_progress_reporter .assert_called_once ()
170
+ call_args = mock_progress_reporter .call_args
171
+ assert_that (call_args .kwargs ["metrics_interval_in_seconds" ], equal_to (45.0 ))
172
+ assert_that (call_args .kwargs ["reporting_frequency" ], equal_to (5000 ))
173
+
174
+ # Verify other parts of the request are still correct
175
+ assert_that (result .pipeline_name , equal_to (pipeline_name ))
176
+ assert_that (result .initialization_arguments .annotations , equal_to (annotations ))
177
+ assert_that (result .initialization_arguments .step_outbox_size , equal_to (10001 ))
178
+
179
+
46
180
def test_spinner_on_start (mocker ):
47
181
spinner = SpinnerProgressIndicator (mocker .Mock (), "pipeline_name" )
48
182
spinner .on_start ()
0 commit comments