24
24
"question_uuid" : QUESTION_UUID ,
25
25
"parent_question_uuid" : "1d897229-155d-498d-b6ae-21960fab3754" ,
26
26
"originator_question_uuid" : "fb6cf9a3-84fb-45ce-a4da-0d2257bec319" ,
27
- "forward_logs" : True ,
27
+ "retry_count" : "0" ,
28
+ "forward_logs" : "1" ,
29
+ "save_diagnostics" : "SAVE_DIAGNOSTICS_ON_CRASH" ,
30
+ "cpus" : "1" ,
31
+ "memory" : "2Gi" ,
32
+ "ephemeral_storage" : "256Mi" ,
28
33
}
29
34
30
35
@@ -75,9 +80,16 @@ def test_store_pub_sub_event_in_bigquery(self):
75
80
"datetime" : "2024-04-11T09:26:39.144818" ,
76
81
"uuid" : "c8bda9fa-f072-4330-92b1-96920d06b28d" ,
77
82
"kind" : "heart" ,
78
- "event" : {"some" : "data" },
83
+ "event" : {
84
+ "some" : "data" ,
85
+ },
79
86
"other_attributes" : {
80
- "forward_logs" : True ,
87
+ "retry_count" : "0" ,
88
+ "forward_logs" : "1" ,
89
+ "save_diagnostics" : "SAVE_DIAGNOSTICS_ON_CRASH" ,
90
+ "cpus" : "1" ,
91
+ "memory" : "2Gi" ,
92
+ "ephemeral_storage" : "256Mi" ,
81
93
},
82
94
"parent" : "octue/parent-test-service:5.6.3" ,
83
95
"originator" : "octue/ancestor-test-service:5.6.3" ,
@@ -93,13 +105,51 @@ def test_store_pub_sub_event_in_bigquery(self):
93
105
},
94
106
)
95
107
108
+ def test_store_pub_sub_event_in_bigquery_with_no_parent_question_uuid (self ):
109
+ """Test that an event with no `parent_question_uuid` attribute is handled correctly."""
110
+ attributes = copy .copy (EVENT_ATTRIBUTES )
111
+ attributes .pop ("parent_question_uuid" )
112
+
113
+ cloud_event = MockCloudEvent (
114
+ data = {
115
+ "message" : {
116
+ "data" : base64 .b64encode (b'{"kind": "heart", "some": "data"}' ),
117
+ "attributes" : attributes ,
118
+ "messageId" : "1234" ,
119
+ }
120
+ }
121
+ )
122
+
123
+ mock_big_query_client = MockBigQueryClient ()
124
+
125
+ with patch ("functions.event_handler.main.BigQueryClient" , return_value = mock_big_query_client ):
126
+ handle_event (cloud_event )
127
+
128
+ self .assertIsNone (mock_big_query_client .inserted_rows [0 ][0 ]["parent_question_uuid" ])
129
+
96
130
def test_question_is_dispatched_to_kueue (self ):
97
131
"""Test that questions are dispatched to Kueue correctly."""
132
+ event_attributes = {
133
+ "datetime" : "2024-04-11T09:26:39.144818" ,
134
+ "uuid" : "c8bda9fa-f072-4330-92b1-96920d06b28d" ,
135
+ "parent" : "octue/parent-test-service:5.6.3" ,
136
+ "originator" : "octue/ancestor-test-service:5.6.3" ,
137
+ "sender" : "octue/test-service:5.6.3" ,
138
+ "sender_type" : "PARENT" ,
139
+ "sender_sdk_version" : "1.0.3" ,
140
+ "recipient" : SRUID ,
141
+ "question_uuid" : QUESTION_UUID ,
142
+ "parent_question_uuid" : "1d897229-155d-498d-b6ae-21960fab3754" ,
143
+ "originator_question_uuid" : "fb6cf9a3-84fb-45ce-a4da-0d2257bec319" ,
144
+ "retry_count" : "0" ,
145
+ "forward_logs" : "1" ,
146
+ }
147
+
98
148
cloud_event = MockCloudEvent (
99
149
data = {
100
150
"message" : {
101
151
"data" : base64 .b64encode (b'{"kind": "question", "input_values": {"some": "data"}}' ),
102
- "attributes" : copy .copy (EVENT_ATTRIBUTES ),
152
+ "attributes" : copy .copy (event_attributes ),
103
153
"messageId" : "1234" ,
104
154
}
105
155
}
@@ -118,11 +168,13 @@ def test_question_is_dispatched_to_kueue(self):
118
168
self .assertEqual (container .name , job .metadata .name )
119
169
self .assertEqual (container .image , f"some-artifact-registry-url/{ SRUID } " )
120
170
self .assertEqual (container .command , ["octue" , "question" , "ask" , "local" ])
171
+
172
+ # Check the default resource requirements are used.
121
173
self .assertEqual (container .resources , {"requests" : {"cpu" : 1 , "ephemeral-storage" : "1Gi" , "memory" : "500Mi" }})
122
174
123
175
self .assertEqual (
124
176
container .args ,
125
- ["--attributes" , json .dumps (EVENT_ATTRIBUTES ), "--input-values" , '{"some": "data"}' ],
177
+ ["--attributes" , json .dumps (event_attributes ), "--input-values" , '{"some": "data"}' ],
126
178
)
127
179
128
180
environment_variables = [variable .to_dict () for variable in container .env ]
0 commit comments