|
| 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 |
0 commit comments