@@ -98,6 +98,65 @@ func TestInsertRemove(t *testing.T) {
98
98
assert .Equal (t , 99 , len (sorted ))
99
99
}
100
100
101
+ func TestRemoveWithSamePriorityAndTime (t * testing.T ) {
102
+ // Create a sorted requests list
103
+ sorted := sortedRequests {}
104
+
105
+ // Create allocations with same priority and creation time
106
+ // but different allocation keys
107
+ baseTime := time .Now ()
108
+ alloc1 := & Allocation {
109
+ createTime : baseTime ,
110
+ priority : 10 ,
111
+ allocationKey : "alloc-1" ,
112
+ }
113
+ alloc2 := & Allocation {
114
+ createTime : baseTime ,
115
+ priority : 10 ,
116
+ allocationKey : "alloc-2" ,
117
+ }
118
+ alloc3 := & Allocation {
119
+ createTime : baseTime ,
120
+ priority : 10 ,
121
+ allocationKey : "alloc-3" ,
122
+ }
123
+
124
+ // Insert the allocations
125
+ sorted .insert (alloc1 )
126
+ sorted .insert (alloc2 )
127
+ sorted .insert (alloc3 )
128
+
129
+ // Verify all allocations are in the list
130
+ assert .Equal (t , 3 , len (sorted ))
131
+ assert .Assert (t , askPresent (alloc1 , sorted ), "alloc1 should be present" )
132
+ assert .Assert (t , askPresent (alloc2 , sorted ), "alloc2 should be present" )
133
+ assert .Assert (t , askPresent (alloc3 , sorted ), "alloc3 should be present" )
134
+
135
+ // Try to remove alloc2
136
+ sorted .remove (alloc2 )
137
+
138
+ // Verify alloc2 is removed but alloc1 and alloc3 are still there
139
+ assert .Equal (t , 2 , len (sorted ))
140
+ assert .Assert (t , askPresent (alloc1 , sorted ), "alloc1 should still be present" )
141
+ assert .Assert (t , ! askPresent (alloc2 , sorted ), "alloc2 should be removed" )
142
+ assert .Assert (t , askPresent (alloc3 , sorted ), "alloc3 should still be present" )
143
+
144
+ // Try to remove alloc1
145
+ sorted .remove (alloc1 )
146
+
147
+ // Verify alloc1 is removed and only alloc3 remains
148
+ assert .Equal (t , 1 , len (sorted ))
149
+ assert .Assert (t , ! askPresent (alloc1 , sorted ), "alloc1 should be removed" )
150
+ assert .Assert (t , askPresent (alloc3 , sorted ), "alloc3 should still be present" )
151
+
152
+ // Try to remove alloc3
153
+ sorted .remove (alloc3 )
154
+
155
+ // Verify all allocations are removed
156
+ assert .Equal (t , 0 , len (sorted ))
157
+ assert .Assert (t , ! askPresent (alloc3 , sorted ), "alloc3 should be removed" )
158
+ }
159
+
101
160
func askPresent (ask * Allocation , asks []* Allocation ) bool {
102
161
for _ , a := range asks {
103
162
if a .allocationKey == ask .allocationKey {
0 commit comments