Commit ede96b7 1 parent f8b311d commit ede96b7 Copy full SHA for ede96b7
File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -463,14 +463,15 @@ func (t *Tree) Terminate(name string) error {
463
463
// trees, if the tree is not started yet, it is going to block. If the tree is
464
464
// halted, it is going to fail with ErrTreeNotRunning.
465
465
func (t * Tree ) Delete (name string ) error {
466
- if err := t .Terminate (name ); err != nil {
466
+ if err := t .Terminate (name ); err != nil && ! errors . Is ( err , ErrProcessNotRunning ) {
467
467
return err
468
468
}
469
469
t .semaphore .Lock ()
470
470
defer t .semaphore .Unlock ()
471
471
t .childrenOrder = slices .DeleteFunc (t .childrenOrder , func (cp * childProcess ) bool {
472
472
return cp .spec .Name == name
473
473
})
474
+ delete (t .children , name )
474
475
return nil
475
476
}
476
477
Original file line number Diff line number Diff line change @@ -1148,3 +1148,36 @@ func TestTerminateNoExistingChildProcess(t *testing.T) {
1148
1148
t .Fatal ("unexpected error" , err )
1149
1149
}
1150
1150
}
1151
+
1152
+ func Test_deleteFinishedTransient (t * testing.T ) {
1153
+ tree := oversight .New (
1154
+ oversight .NeverHalt (),
1155
+ )
1156
+ ready := make (chan struct {})
1157
+ tree .Add (oversight.ChildProcessSpecification {
1158
+ Restart : oversight .Permanent (),
1159
+ Start : func (ctx context.Context ) error {
1160
+ <- ctx .Done ()
1161
+ return nil
1162
+ },
1163
+ })
1164
+ tree .Add (oversight.ChildProcessSpecification {
1165
+ Name : "failed-transient" ,
1166
+ Restart : oversight .Transient (),
1167
+ Start : func (context.Context ) error {
1168
+ t .Log ("running transient process" )
1169
+ defer close (ready )
1170
+ return nil
1171
+ },
1172
+ })
1173
+ ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
1174
+ t .Cleanup (cancel )
1175
+ go tree .Start (ctx )
1176
+ <- ready
1177
+ time .Sleep (1 * time .Second )
1178
+ err := tree .Delete ("failed-transient" )
1179
+ if err != nil {
1180
+ t .Fatal (err )
1181
+ }
1182
+ <- ctx .Done ()
1183
+ }
You can’t perform that action at this time.
0 commit comments