1
1
#[ cfg( test) ]
2
2
mod tests {
3
+ use std:: collections:: HashMap ;
4
+
3
5
use anyhow:: Result ;
4
6
use bytes:: Bytes ;
5
7
use data_model:: {
6
8
test_objects:: tests:: { mock_graph_a, TEST_NAMESPACE } ,
9
+ GraphInvocationCtx ,
7
10
InvocationPayload ,
8
11
NodeOutput ,
9
12
} ;
10
13
use futures:: stream;
14
+ use indexify_utils:: get_epoch_time_in_ms;
11
15
use state_store:: {
12
16
requests:: {
13
17
CreateOrUpdateComputeGraphRequest ,
@@ -32,81 +36,104 @@ mod tests {
32
36
} = test_srv. service ;
33
37
34
38
// Create a compute graph
35
- let compute_graph = mock_graph_a ( "image_hash" . to_string ( ) ) ;
36
- indexify_state
37
- . write ( StateMachineUpdateRequest {
38
- payload : RequestPayload :: CreateOrUpdateComputeGraph (
39
- CreateOrUpdateComputeGraphRequest {
40
- namespace : TEST_NAMESPACE . to_string ( ) ,
41
- compute_graph : compute_graph. clone ( ) ,
42
- upgrade_tasks_to_current_version : false ,
43
- } ,
44
- ) ,
45
- processed_state_changes : vec ! [ ] ,
46
- } )
47
- . await ?;
39
+ let compute_graph = {
40
+ let mut compute_graph = mock_graph_a ( "image_hash" . to_string ( ) ) . clone ( ) ;
41
+ let data = "code" ;
42
+ let path = format ! ( "{}" , & compute_graph. code. path) ;
43
+
44
+ let data_stream = Box :: pin ( stream:: once ( async { Ok ( Bytes :: from ( data) ) } ) ) ;
45
+ let res = blob_storage. put ( & path, data_stream) . await ?;
46
+ compute_graph. code . path = res. url ;
47
+
48
+ indexify_state
49
+ . write ( StateMachineUpdateRequest {
50
+ payload : RequestPayload :: CreateOrUpdateComputeGraph (
51
+ CreateOrUpdateComputeGraphRequest {
52
+ namespace : TEST_NAMESPACE . to_string ( ) ,
53
+ compute_graph : compute_graph. clone ( ) ,
54
+ upgrade_tasks_to_current_version : false ,
55
+ } ,
56
+ ) ,
57
+ processed_state_changes : vec ! [ ] ,
58
+ } )
59
+ . await ?;
48
60
49
- let data = "aaaa" ;
50
- let path = "qqqq" ;
51
- let data_stream = Box :: pin ( stream:: once ( async { Ok ( Bytes :: from ( data) ) } ) ) ;
52
- let res = blob_storage. put ( path, data_stream) . await ?;
53
-
54
- // Create a graph invocation
55
- let invocation = InvocationPayload {
56
- id : "invocation_id" . to_string ( ) ,
57
- namespace : TEST_NAMESPACE . to_string ( ) ,
58
- compute_graph_name : compute_graph. name . clone ( ) ,
59
- payload : data_model:: DataPayload {
60
- path : res. url . clone ( ) ,
61
- size : res. size_bytes ,
62
- sha256_hash : res. sha256_hash . clone ( ) ,
63
- } ,
64
- created_at : 5 ,
65
- encoding : "application/octet-stream" . to_string ( ) ,
61
+ compute_graph
66
62
} ;
67
63
68
- indexify_state. db . put_cf (
69
- & IndexifyObjectsColumns :: GraphInvocations . cf_db ( & indexify_state. db ) ,
70
- invocation. key ( ) . as_bytes ( ) ,
71
- & JsonEncoder :: encode ( & invocation) ?,
72
- ) ?;
73
-
74
- let output = NodeOutput {
75
- id : "id" . to_string ( ) ,
76
- namespace : TEST_NAMESPACE . to_string ( ) ,
77
- compute_fn_name : "fn_a" . to_string ( ) ,
78
- compute_graph_name : "graph_A" . to_string ( ) ,
79
- invocation_id : "invocation_id" . to_string ( ) ,
80
- payload : data_model:: OutputPayload :: Fn ( data_model:: DataPayload {
81
- path : res. url . clone ( ) ,
82
- size : res. size_bytes ,
83
- sha256_hash : res. sha256_hash . clone ( ) ,
84
- } ) ,
85
- errors : None ,
86
- reduced_state : false ,
87
- created_at : 5 ,
88
- encoding : "application/octet-stream" . to_string ( ) ,
64
+ let res = {
65
+ let data = "invocation_payload" ;
66
+ let path = "invocation_payload" ;
67
+ let data_stream = Box :: pin ( stream:: once ( async { Ok ( Bytes :: from ( data) ) } ) ) ;
68
+ let res = blob_storage. put ( path, data_stream) . await ?;
69
+
70
+ // Create a graph invocation
71
+ let invocation = InvocationPayload {
72
+ id : "invocation_id" . to_string ( ) ,
73
+ namespace : TEST_NAMESPACE . to_string ( ) ,
74
+ compute_graph_name : compute_graph. name . clone ( ) ,
75
+ payload : data_model:: DataPayload {
76
+ path : res. url . clone ( ) ,
77
+ size : res. size_bytes ,
78
+ sha256_hash : res. sha256_hash . clone ( ) ,
79
+ } ,
80
+ created_at : get_epoch_time_in_ms ( ) ,
81
+ encoding : "application/octet-stream" . to_string ( ) ,
82
+ } ;
83
+
84
+ indexify_state. db . put_cf (
85
+ & IndexifyObjectsColumns :: GraphInvocations . cf_db ( & indexify_state. db ) ,
86
+ invocation. key ( ) . as_bytes ( ) ,
87
+ & JsonEncoder :: encode ( & invocation) ?,
88
+ ) ?;
89
+
90
+ indexify_state. db . put_cf (
91
+ & IndexifyObjectsColumns :: GraphInvocationCtx . cf_db ( & indexify_state. db ) ,
92
+ invocation. key ( ) . as_bytes ( ) ,
93
+ & JsonEncoder :: encode ( & GraphInvocationCtx {
94
+ invocation_id : invocation. id . clone ( ) ,
95
+ compute_graph_name : compute_graph. name . clone ( ) ,
96
+ namespace : TEST_NAMESPACE . to_string ( ) ,
97
+ graph_version : compute_graph. version . clone ( ) ,
98
+ completed : false ,
99
+ outcome : data_model:: GraphInvocationOutcome :: Failure ,
100
+ outstanding_tasks : 0 ,
101
+ fn_task_analytics : HashMap :: new ( ) ,
102
+ created_at : get_epoch_time_in_ms ( ) ,
103
+ } ) ?,
104
+ ) ?;
105
+
106
+ let output = NodeOutput {
107
+ id : "id" . to_string ( ) ,
108
+ namespace : TEST_NAMESPACE . to_string ( ) ,
109
+ compute_fn_name : "fn_a" . to_string ( ) ,
110
+ compute_graph_name : compute_graph. name . clone ( ) ,
111
+ invocation_id : invocation. id . clone ( ) ,
112
+ payload : data_model:: OutputPayload :: Fn ( data_model:: DataPayload {
113
+ path : res. url . clone ( ) ,
114
+ size : res. size_bytes ,
115
+ sha256_hash : res. sha256_hash . clone ( ) ,
116
+ } ) ,
117
+ errors : None ,
118
+ reduced_state : false ,
119
+ created_at : 5 ,
120
+ encoding : "application/octet-stream" . to_string ( ) ,
121
+ } ;
122
+ let key = output. key ( & output. invocation_id ) ;
123
+ let serialized_output = JsonEncoder :: encode ( & output) ?;
124
+ indexify_state. db . put_cf (
125
+ & IndexifyObjectsColumns :: FnOutputs . cf_db ( & indexify_state. db ) ,
126
+ key,
127
+ & serialized_output,
128
+ ) ?;
129
+
130
+ blob_storage. read_bytes ( & res. url ) . await ?;
131
+
132
+ res
89
133
} ;
90
- let key = output. key ( & output. invocation_id ) ;
91
- let serialized_output = JsonEncoder :: encode ( & output) ?;
92
- indexify_state. db . put_cf (
93
- & IndexifyObjectsColumns :: FnOutputs . cf_db ( & indexify_state. db ) ,
94
- key,
95
- & serialized_output,
96
- ) ?;
97
-
98
- blob_storage. read_bytes ( & res. url ) . await ?;
99
-
100
- let request = RequestPayload :: TombstoneComputeGraph ( DeleteComputeGraphRequest {
101
- namespace : TEST_NAMESPACE . to_string ( ) ,
102
- name : compute_graph. name . clone ( ) ,
103
- } ) ;
104
- indexify_state
105
- . write ( StateMachineUpdateRequest {
106
- payload : request,
107
- processed_state_changes : vec ! [ ] ,
108
- } )
109
- . await ?;
134
+
135
+ let urls = indexify_state. reader ( ) . get_gc_urls ( None ) ?;
136
+ assert ! ( urls. is_empty( ) , "all gc urls are empty: {:?}" , urls) ;
110
137
111
138
indexify_state
112
139
. write ( StateMachineUpdateRequest {
@@ -118,15 +145,20 @@ mod tests {
118
145
} )
119
146
. await ?;
120
147
148
+ let urls = indexify_state. reader ( ) . get_gc_urls ( None ) ?;
149
+ assert ! (
150
+ !urls. is_empty( ) ,
151
+ "all gc urls should not be empty: {:?}" ,
152
+ urls
153
+ ) ;
154
+
121
155
gc_executor. lock ( ) . await . run ( ) . await ?;
122
156
123
157
let urls = indexify_state. reader ( ) . get_gc_urls ( None ) ?;
124
- assert ! ( urls. is_empty( ) , "all gc urls are empty" ) ;
158
+ assert ! ( urls. is_empty( ) , "all gc urls are empty: {:?}" , urls ) ;
125
159
126
- assert ! (
127
- blob_storage. read_bytes( & res. url) . await . is_err( ) ,
128
- "file is deleted"
129
- ) ;
160
+ let read_res = blob_storage. read_bytes ( & res. url ) . await ;
161
+ assert ! ( read_res. is_err( ) , "file is not deleted: {:#?}" , read_res) ;
130
162
131
163
Ok ( ( ) )
132
164
}
0 commit comments