Skip to content

Commit 01320ed

Browse files
Add missing struct fields to match Go implementation
Conditions: - Add locationname field for location-based filtering FunctionSpec: - Add channels field for real-time channel support Process: - Fix in/out types from Array{String} to Array{Any} to match Go's []interface{} for mixed-type input/output Add comprehensive unit tests for core structs in core_tests.jl Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cca223a commit 01320ed

3 files changed

Lines changed: 233 additions & 26 deletions

File tree

src/core.jl

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,29 +130,31 @@ end
130130
colonyname::String = ""
131131
executornames::Union{Array{String, 1}, Nothing} = String[]
132132
executortype::String = ""
133+
locationname::String = ""
133134
dependencies::Union{Array{String, 1}, Nothing} = String[]
134135
nodes::Int64 = 1
135136
cpu::String = "1000m"
136-
processes::Int64 = 0
137-
processespernode::Int64 = 1
137+
processes::Int64 = 0
138+
processespernode::Int64 = 1
138139
mem::String = "0Gi"
139140
storage::String = "0Gi"
140141
gpu::GPU = GPU("", "", 0, 0)
141-
walltime::Int64 = 60
142+
walltime::Int64 = 60
142143

143144
function Conditions(
144145
colonyname::String,
145146
executornames::Union{Array{String, 1}, Nothing},
146147
executortype::String,
147148
dependencies::Union{Array{String, 1}, Nothing} = []
148149
)
149-
new(colonyname, executornames, executortype, dependencies, 1, "", 1, 1, "", "", GPU("", "", 0, 0), 0)
150+
new(colonyname, executornames, executortype, "", dependencies, 1, "", 1, 1, "", "", GPU("", "", 0, 0), 0)
150151
end
151152

152153
function Conditions(
153154
colonyname::String,
154155
executornames::Union{Array{String, 1}, Nothing},
155156
executortype::String,
157+
locationname::String,
156158
dependencies::Union{Array{String, 1}, Nothing},
157159
nodes::Int64,
158160
cpu::String,
@@ -163,7 +165,7 @@ end
163165
gpu::GPU,
164166
walltime::Int64
165167
)
166-
new(colonyname, executornames, executortype, dependencies, nodes, cpu, processes, processespernode, mem, storage, gpu, walltime)
168+
new(colonyname, executornames, executortype, locationname, dependencies, nodes, cpu, processes, processespernode, mem, storage, gpu, walltime)
167169
end
168170
end
169171

@@ -212,7 +214,7 @@ end
212214
@kwdef struct FunctionSpec
213215
nodename::String = ""
214216
funcname::String = ""
215-
args::Union{Array{Any, 1}, Nothing} = []
217+
args::Union{Array{Any, 1}, Nothing} = []
216218
kwargs::Dict{String, Any} = Dict{Any, Any}()
217219
priority::Int64 = 0
218220
maxwaittime::Int64 = 0
@@ -222,22 +224,24 @@ end
222224
label::String = ""
223225
fs::Filesystem = Filesystem()
224226
env::Dict{String, String} = Dict{Any, Any}()
227+
channels::Union{Array{String, 1}, Nothing} = String[]
225228

226229
function FunctionSpec(
227-
nodename::String,
228-
funcname::String,
229-
args::Union{Array{Any, 1}, Nothing},
230-
kwargs::Dict{Any, Any},
231-
priority::Int64,
232-
maxwaittime::Int64,
233-
maxexectime::Int64,
234-
maxretries::Int64,
235-
conditions::Conditions,
236-
label::String,
237-
fs::Filesystem,
238-
env::Dict{Any, Any}
230+
nodename::String,
231+
funcname::String,
232+
args::Union{Array{Any, 1}, Nothing},
233+
kwargs::Dict{Any, Any},
234+
priority::Int64,
235+
maxwaittime::Int64,
236+
maxexectime::Int64,
237+
maxretries::Int64,
238+
conditions::Conditions,
239+
label::String,
240+
fs::Filesystem,
241+
env::Dict{Any, Any},
242+
channels::Union{Array{String, 1}, Nothing} = String[]
239243
)
240-
new(nodename, funcname, args, kwargs, priority, maxwaittime, maxexectime, maxretries, conditions, label, fs, env)
244+
new(nodename, funcname, args, kwargs, priority, maxwaittime, maxexectime, maxretries, conditions, label, fs, env, channels)
241245
end
242246

243247
function FunctionSpec(
@@ -264,10 +268,11 @@ end
264268
conditions,
265269
label,
266270
Filesystem(),
267-
Dict{String, String}(k => string(v) for (k, v) in env)
271+
Dict{String, String}(k => string(v) for (k, v) in env),
272+
String[]
268273
)
269274
end
270-
275+
271276
function FunctionSpec(
272277
nodename::String,
273278
funcname::String,
@@ -291,8 +296,9 @@ end
291296
conditions,
292297
label,
293298
Filesystem(),
294-
Dict{String, String}())
295-
299+
Dict{String, String}(),
300+
String[]
301+
)
296302
end
297303
end
298304

@@ -317,7 +323,7 @@ end
317323

318324
Base.@kwdef struct Process
319325
processid::String
320-
initiatorid::String
326+
initiatorid::String
321327
initiatorname::String
322328
assignedexecutorid::String
323329
isassigned::Bool
@@ -335,8 +341,8 @@ Base.@kwdef struct Process
335341
parents::Union{Array{String,1},Nothing} = []
336342
children::Union{Array{String,1},Nothing} = []
337343
processgraphid::String = ""
338-
in::Union{Array{String,1},Nothing} = []
339-
out::Union{Array{String,1},Nothing} = []
344+
in::Union{Array{Any,1},Nothing} = []
345+
out::Union{Array{Any,1},Nothing} = []
340346
errors::Union{Array{String,1},Nothing} = []
341347
end
342348

test/core_tests.jl

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
using Test
2+
using Colonies
3+
4+
# ============================================================================
5+
# Conditions Tests
6+
# ============================================================================
7+
8+
function test_conditions_with_locationname()
9+
cond = Colonies.Conditions(
10+
colonyname = "test-colony",
11+
executornames = ["executor1"],
12+
executortype = "test-type",
13+
locationname = "datacenter-1",
14+
dependencies = String[],
15+
nodes = 2,
16+
cpu = "2000m",
17+
processes = 4,
18+
processespernode = 2,
19+
mem = "4Gi",
20+
storage = "10Gi",
21+
gpu = Colonies.GPU("nvidia-a100", "40Gi", 1, 1),
22+
walltime = 3600
23+
)
24+
cond.locationname == "datacenter-1" && cond.nodes == 2
25+
end
26+
27+
function test_conditions_default_locationname()
28+
cond = Colonies.Conditions("test-colony", String[], "test-type", String[])
29+
cond.locationname == ""
30+
end
31+
32+
# ============================================================================
33+
# FunctionSpec Tests
34+
# ============================================================================
35+
36+
function test_functionspec_with_channels()
37+
cond = Colonies.Conditions("test-colony", String[], "test-type", String[])
38+
# Use the full constructor with correct types
39+
spec = Colonies.FunctionSpec(
40+
"node1", # nodename
41+
"test-func", # funcname
42+
Any["arg1", 123, true], # args
43+
Dict{Any, Any}("key1" => "value1"), # kwargs
44+
1, # priority
45+
60, # maxwaittime
46+
300, # maxexectime
47+
3, # maxretries
48+
cond, # conditions
49+
"test-label", # label
50+
Colonies.Filesystem(), # fs
51+
Dict{Any, Any}("VAR1" => "val1"), # env
52+
["channel1", "channel2"] # channels
53+
)
54+
spec.channels == ["channel1", "channel2"]
55+
end
56+
57+
function test_functionspec_default_channels()
58+
cond = Colonies.Conditions("test-colony", String[], "test-type", String[])
59+
spec = Colonies.FunctionSpec("node1", "test-func", String[], 1, 60, 300, 3, cond, "label")
60+
spec.channels == String[]
61+
end
62+
63+
# ============================================================================
64+
# Process Tests
65+
# ============================================================================
66+
67+
function test_process_in_out_any_type()
68+
cond = Colonies.Conditions("test-colony", String[], "test-type", String[])
69+
spec = Colonies.FunctionSpec("node1", "test-func", String[], 1, 60, 300, 3, cond, "label")
70+
71+
# Create a process with mixed-type input/output
72+
proc = Colonies.Process(
73+
processid = "test-id",
74+
initiatorid = "initiator-id",
75+
initiatorname = "initiator-name",
76+
assignedexecutorid = "",
77+
isassigned = false,
78+
state = Colonies.WAITING,
79+
prioritytime = UInt64(0),
80+
submissiontime = "",
81+
starttime = "",
82+
endtime = "",
83+
waitdeadline = "",
84+
execdeadline = "",
85+
retries = UInt16(0),
86+
attributes = Colonies.Attribute[],
87+
spec = spec,
88+
waitforparents = false,
89+
parents = String[],
90+
children = String[],
91+
processgraphid = "",
92+
in = Any["string-input", 123, Dict("key" => "value")],
93+
out = Any["result", 456, true],
94+
errors = String[]
95+
)
96+
97+
# Verify mixed types are preserved
98+
proc.in[1] == "string-input" &&
99+
proc.in[2] == 123 &&
100+
proc.out[1] == "result" &&
101+
proc.out[2] == 456 &&
102+
proc.out[3] == true
103+
end
104+
105+
function test_process_empty_in_out()
106+
cond = Colonies.Conditions("test-colony", String[], "test-type", String[])
107+
spec = Colonies.FunctionSpec("node1", "test-func", String[], 1, 60, 300, 3, cond, "label")
108+
109+
proc = Colonies.Process(
110+
processid = "test-id",
111+
initiatorid = "initiator-id",
112+
initiatorname = "initiator-name",
113+
assignedexecutorid = "",
114+
isassigned = false,
115+
state = Colonies.WAITING,
116+
prioritytime = UInt64(0),
117+
submissiontime = "",
118+
starttime = "",
119+
endtime = "",
120+
waitdeadline = "",
121+
execdeadline = "",
122+
retries = UInt16(0),
123+
attributes = Colonies.Attribute[],
124+
spec = spec,
125+
waitforparents = false
126+
)
127+
128+
isempty(proc.in) && isempty(proc.out)
129+
end
130+
131+
# ============================================================================
132+
# GPU Tests
133+
# ============================================================================
134+
135+
function test_gpu_struct()
136+
gpu = Colonies.GPU("nvidia-a100", "80Gi", 4, 2)
137+
gpu.name == "nvidia-a100" && gpu.mem == "80Gi" && gpu.count == 4 && gpu.nodecount == 2
138+
end
139+
140+
function test_gpu_default_nodecount()
141+
gpu = Colonies.GPU("nvidia-v100", "32Gi", 2)
142+
gpu.nodecount == 0
143+
end
144+
145+
# ============================================================================
146+
# ProcessResult Tests
147+
# ============================================================================
148+
149+
function test_processresult_struct()
150+
result = Colonies.ProcessResult(
151+
processid = "proc-123",
152+
state = Colonies.SUCCESS,
153+
spec = Dict{String, Any}("funcname" => "test"),
154+
output = Any["result1", 42],
155+
errors = Any[]
156+
)
157+
result.processid == "proc-123" && result.state == Colonies.SUCCESS
158+
end
159+
160+
# ============================================================================
161+
# ChannelEntry Tests
162+
# ============================================================================
163+
164+
function test_channelentry_struct()
165+
entry = Colonies.ChannelEntry(
166+
sequence = 1,
167+
data = "test-data",
168+
msgtype = "data",
169+
inreplyto = 0
170+
)
171+
entry.sequence == 1 && entry.data == "test-data" && entry.msgtype == "data"
172+
end
173+
174+
# ============================================================================
175+
# Run Tests
176+
# ============================================================================
177+
178+
@testset "Core Struct Tests" begin
179+
# Conditions tests
180+
@test test_conditions_with_locationname()
181+
@test test_conditions_default_locationname()
182+
183+
# FunctionSpec tests
184+
@test test_functionspec_with_channels()
185+
@test test_functionspec_default_channels()
186+
187+
# Process tests
188+
@test test_process_in_out_any_type()
189+
@test test_process_empty_in_out()
190+
191+
# GPU tests
192+
@test test_gpu_struct()
193+
@test test_gpu_default_nodecount()
194+
195+
# ProcessResult tests
196+
@test test_processresult_struct()
197+
198+
# ChannelEntry tests
199+
@test test_channelentry_struct()
200+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ using Test
22
using Colonies
33

44
include("crypto_tests.jl")
5+
include("core_tests.jl")
56
include("colonies_tests.jl")

0 commit comments

Comments
 (0)