Skip to content

Commit 93b6c98

Browse files
committed
[core] Fix DCS op availability check + unit test
1 parent c5fdca8 commit 93b6c98

3 files changed

Lines changed: 209 additions & 10 deletions

File tree

Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ INSTALL_WHAT:=$(patsubst %, install_%, $(WHAT))
7272
GENERATE_DIRS := ./apricot ./coconut/cmd ./common/runtype ./common/system ./core ./core/integration/ccdb ./core/integration/dcs ./core/integration/ddsched ./core/integration/kafka ./core/integration/odc ./executor ./walnut ./core/integration/trg ./core/integration/bookkeeping
7373
SRC_DIRS := ./apricot ./cmd/* ./core ./coconut ./executor ./common ./configuration ./occ/peanut ./walnut
7474
TEST_DIRS := ./configuration/cfgbackend
75-
GO_TEST_DIRS := ./core/repos
75+
GO_TEST_DIRS := ./core/repos ./core/integration/dcs
7676

7777
# Use linker flags to provide version/build settings to the target
7878
PROD :=-X=$(REPOPATH)/common/product
@@ -148,18 +148,18 @@ endif
148148
done
149149

150150
test:
151-
@echo -e "[Ginkgo] \033[1;33mgo test -v --race\033[0m $(TEST_DIRS)\033[0m"
152-
@$(BUILD_FLAGS) go test -v --race $(TEST_DIRS) -ginkgo.show-node-events
151+
@echo -e "[Ginkgo] \033[1;33mgo test -v\033[0m $(TEST_DIRS)\033[0m"
152+
@$(BUILD_FLAGS) go test -v $(TEST_DIRS) -ginkgo.show-node-events
153153

154-
@echo -e "\n[gotest] \033[1;33mgo test -v --race\033[0m $(GO_TEST_DIRS)\033[0m"
155-
@$(BUILD_FLAGS) go test -v --race $(GO_TEST_DIRS)
154+
@echo -e "\n[gotest] \033[1;33mgo test -v\033[0m $(GO_TEST_DIRS)\033[0m"
155+
@$(BUILD_FLAGS) go test -v $(GO_TEST_DIRS)
156156

157157
debugtest:
158-
@echo -e "[Ginkgo] \033[1;33mgo test -v --race\033[0m $(TEST_DIRS)\033[0m"
159-
@$(BUILD_FLAGS) go test -v --race $(TEST_DIRS) -ginkgo.v -ginkgo.trace -ginkgo.show-node-events
158+
@echo -e "[Ginkgo] \033[1;33mgo test -v\033[0m $(TEST_DIRS)\033[0m"
159+
@$(BUILD_FLAGS) go test -v $(TEST_DIRS) -ginkgo.v -ginkgo.trace -ginkgo.show-node-events
160160

161-
@echo -e "\n[gotest] \033[1;33mgo test -v --race\033[0m $(GO_TEST_DIRS)\033[0m"
162-
@$(BUILD_FLAGS) go test -v --race $(GO_TEST_DIRS)
161+
@echo -e "\n[gotest] \033[1;33mgo test -v\033[0m $(GO_TEST_DIRS)\033[0m"
162+
@$(BUILD_FLAGS) go test -v $(GO_TEST_DIRS)
163163

164164
vet:
165165
go vet $(SRC_DIRS)

core/integration/dcs/structs.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* === This file is part of ALICE O² ===
33
*
4-
* Copyright 2021-2023 CERN and copyright holders of ALICE O².
4+
* Copyright 2021-2024 CERN and copyright holders of ALICE O².
55
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
66
*
77
* This program is free software: you can redistribute it and/or modify
@@ -89,6 +89,10 @@ func (dsm DCSDetectorOpAvailabilityMap) makeDetectorsByStateMap() map[dcspb.Dete
8989
func (dsm DCSDetectorOpAvailabilityMap) compatibleWithDCSOperation(conditionState dcspb.DetectorState) (bool, error) {
9090
detectorsByState := dsm.makeDetectorsByStateMap()
9191

92+
if len(detectorsByState) == 0 {
93+
return true, fmt.Errorf("no detectors provided")
94+
}
95+
9296
detectorsInConditionState, thereAreDetectorsInConditionState := detectorsByState[conditionState]
9397
detectorsInNullState, thereAreDetectorsInNullState := detectorsByState[dcspb.DetectorState_NULL_STATE]
9498

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
* === This file is part of ALICE O² ===
3+
*
4+
* Copyright 2024 CERN and copyright holders of ALICE O².
5+
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* In applying this license CERN does not waive the privileges and
21+
* immunities granted to it by virtue of its status as an
22+
* Intergovernmental Organization or submit itself to any jurisdiction.
23+
*/
24+
25+
package dcs
26+
27+
import (
28+
"testing"
29+
30+
dcspb "github.com/AliceO2Group/Control/core/integration/dcs/protos"
31+
)
32+
33+
func TestDCSDetectorOpAvailabilityMap_compatibleWithDCSOperation(t *testing.T) {
34+
type args struct {
35+
conditionState dcspb.DetectorState
36+
}
37+
tests := []struct {
38+
name string
39+
dsm DCSDetectorOpAvailabilityMap
40+
args args
41+
want bool
42+
wantErr bool
43+
}{
44+
{
45+
name: "condition=PFR_AVAILABLE/states=[]",
46+
dsm: map[dcspb.Detector]dcspb.DetectorState{},
47+
args: args{conditionState: dcspb.DetectorState_PFR_AVAILABLE},
48+
want: true,
49+
wantErr: true,
50+
},
51+
{
52+
name: "condition=PFR_AVAILABLE/states=NULL",
53+
dsm: map[dcspb.Detector]dcspb.DetectorState{
54+
dcspb.Detector_CPV: dcspb.DetectorState_NULL_STATE,
55+
dcspb.Detector_FT0: dcspb.DetectorState_NULL_STATE,
56+
dcspb.Detector_MID: dcspb.DetectorState_NULL_STATE,
57+
},
58+
args: args{conditionState: dcspb.DetectorState_PFR_AVAILABLE},
59+
want: true,
60+
wantErr: true,
61+
},
62+
{
63+
name: "condition=SOR_AVAILABLE/states=NULL",
64+
dsm: map[dcspb.Detector]dcspb.DetectorState{
65+
dcspb.Detector_CPV: dcspb.DetectorState_NULL_STATE,
66+
dcspb.Detector_FT0: dcspb.DetectorState_NULL_STATE,
67+
dcspb.Detector_MID: dcspb.DetectorState_NULL_STATE,
68+
},
69+
args: args{conditionState: dcspb.DetectorState_SOR_AVAILABLE},
70+
want: true,
71+
wantErr: true,
72+
},
73+
{
74+
name: "condition=PFR_AVAILABLE/states=NULL,PFR_UNAVAILABLE",
75+
dsm: map[dcspb.Detector]dcspb.DetectorState{
76+
dcspb.Detector_CPV: dcspb.DetectorState_NULL_STATE,
77+
dcspb.Detector_FT0: dcspb.DetectorState_NULL_STATE,
78+
dcspb.Detector_MID: dcspb.DetectorState_NULL_STATE,
79+
dcspb.Detector_EMC: dcspb.DetectorState_PFR_UNAVAILABLE,
80+
},
81+
args: args{conditionState: dcspb.DetectorState_PFR_AVAILABLE},
82+
want: false,
83+
wantErr: true,
84+
},
85+
{
86+
name: "condition=PFR_AVAILABLE/states=NULL,PFR_AVAILABLE",
87+
dsm: map[dcspb.Detector]dcspb.DetectorState{
88+
dcspb.Detector_CPV: dcspb.DetectorState_NULL_STATE,
89+
dcspb.Detector_FT0: dcspb.DetectorState_NULL_STATE,
90+
dcspb.Detector_MID: dcspb.DetectorState_NULL_STATE,
91+
dcspb.Detector_EMC: dcspb.DetectorState_PFR_AVAILABLE,
92+
},
93+
args: args{conditionState: dcspb.DetectorState_PFR_AVAILABLE},
94+
want: true,
95+
wantErr: true,
96+
},
97+
{
98+
name: "condition=PFR_AVAILABLE/states=NULL,PFR_AVAILABLE,PFR_UNAVAILABLE",
99+
dsm: map[dcspb.Detector]dcspb.DetectorState{
100+
dcspb.Detector_CPV: dcspb.DetectorState_NULL_STATE,
101+
dcspb.Detector_FT0: dcspb.DetectorState_NULL_STATE,
102+
dcspb.Detector_MID: dcspb.DetectorState_NULL_STATE,
103+
dcspb.Detector_EMC: dcspb.DetectorState_PFR_AVAILABLE,
104+
dcspb.Detector_HMP: dcspb.DetectorState_PFR_UNAVAILABLE,
105+
},
106+
args: args{conditionState: dcspb.DetectorState_PFR_AVAILABLE},
107+
want: false,
108+
wantErr: true,
109+
},
110+
{
111+
name: "condition=PFR_AVAILABLE/states=PFR_AVAILABLE,PFR_UNAVAILABLE",
112+
dsm: map[dcspb.Detector]dcspb.DetectorState{
113+
dcspb.Detector_CPV: dcspb.DetectorState_PFR_AVAILABLE,
114+
dcspb.Detector_FT0: dcspb.DetectorState_PFR_AVAILABLE,
115+
dcspb.Detector_MID: dcspb.DetectorState_PFR_AVAILABLE,
116+
dcspb.Detector_EMC: dcspb.DetectorState_PFR_AVAILABLE,
117+
dcspb.Detector_HMP: dcspb.DetectorState_PFR_UNAVAILABLE,
118+
},
119+
args: args{conditionState: dcspb.DetectorState_PFR_AVAILABLE},
120+
want: false,
121+
wantErr: true,
122+
},
123+
{
124+
name: "condition=SOR_AVAILABLE/states=PFR_AVAILABLE,PFR_UNAVAILABLE",
125+
dsm: map[dcspb.Detector]dcspb.DetectorState{
126+
dcspb.Detector_CPV: dcspb.DetectorState_PFR_AVAILABLE,
127+
dcspb.Detector_FT0: dcspb.DetectorState_PFR_AVAILABLE,
128+
dcspb.Detector_MID: dcspb.DetectorState_PFR_AVAILABLE,
129+
dcspb.Detector_EMC: dcspb.DetectorState_PFR_AVAILABLE,
130+
dcspb.Detector_HMP: dcspb.DetectorState_PFR_UNAVAILABLE,
131+
},
132+
args: args{conditionState: dcspb.DetectorState_SOR_AVAILABLE},
133+
want: false,
134+
wantErr: true,
135+
},
136+
{
137+
name: "condition=PFR_AVAILABLE/states=PFR_AVAILABLE,PFR_UNAVAILABLE,DEAD,ERROR,RUN_INHIBIT",
138+
dsm: map[dcspb.Detector]dcspb.DetectorState{
139+
dcspb.Detector_CPV: dcspb.DetectorState_DEAD,
140+
dcspb.Detector_FT0: dcspb.DetectorState_ERROR,
141+
dcspb.Detector_MID: dcspb.DetectorState_RUN_INHIBIT,
142+
dcspb.Detector_EMC: dcspb.DetectorState_PFR_AVAILABLE,
143+
dcspb.Detector_HMP: dcspb.DetectorState_PFR_UNAVAILABLE,
144+
},
145+
args: args{conditionState: dcspb.DetectorState_PFR_AVAILABLE},
146+
want: false,
147+
wantErr: true,
148+
},
149+
{
150+
name: "condition=PFR_AVAILABLE/states=PFR_AVAILABLE",
151+
dsm: map[dcspb.Detector]dcspb.DetectorState{
152+
dcspb.Detector_CPV: dcspb.DetectorState_PFR_AVAILABLE,
153+
dcspb.Detector_FT0: dcspb.DetectorState_PFR_AVAILABLE,
154+
dcspb.Detector_MID: dcspb.DetectorState_PFR_AVAILABLE,
155+
dcspb.Detector_EMC: dcspb.DetectorState_PFR_AVAILABLE,
156+
dcspb.Detector_HMP: dcspb.DetectorState_PFR_AVAILABLE,
157+
},
158+
args: args{conditionState: dcspb.DetectorState_PFR_AVAILABLE},
159+
want: true,
160+
wantErr: false,
161+
},
162+
{
163+
name: "condition=SOR_AVAILABLE/states=PFR_AVAILABLE",
164+
dsm: map[dcspb.Detector]dcspb.DetectorState{
165+
dcspb.Detector_CPV: dcspb.DetectorState_PFR_AVAILABLE,
166+
dcspb.Detector_FT0: dcspb.DetectorState_PFR_AVAILABLE,
167+
dcspb.Detector_MID: dcspb.DetectorState_PFR_AVAILABLE,
168+
dcspb.Detector_EMC: dcspb.DetectorState_PFR_AVAILABLE,
169+
dcspb.Detector_HMP: dcspb.DetectorState_PFR_AVAILABLE,
170+
},
171+
args: args{conditionState: dcspb.DetectorState_SOR_AVAILABLE},
172+
want: false,
173+
wantErr: true,
174+
},
175+
}
176+
for _, tt := range tests {
177+
t.Run(tt.name, func(t *testing.T) {
178+
got, err := tt.dsm.compatibleWithDCSOperation(tt.args.conditionState)
179+
if (err != nil) != tt.wantErr {
180+
t.Errorf("compatibleWithDCSOperation() error = %v, wantErr %v", err, tt.wantErr)
181+
return
182+
} else if (err != nil) == tt.wantErr {
183+
t.Logf("compatibleWithDCSOperation() error = %v, wantErr %v", err, tt.wantErr)
184+
}
185+
186+
if got != tt.want {
187+
if err != nil {
188+
t.Errorf("compatibleWithDCSOperation() got = %v, want %v, error = %s", got, tt.want, err.Error())
189+
} else {
190+
t.Errorf("compatibleWithDCSOperation() got = %v, want %v", got, tt.want)
191+
}
192+
}
193+
})
194+
}
195+
}

0 commit comments

Comments
 (0)