@@ -21,6 +21,7 @@ import (
21
21
"os"
22
22
"path/filepath"
23
23
"sync"
24
+ "sync/atomic"
24
25
"testing"
25
26
"time"
26
27
@@ -42,6 +43,7 @@ import (
42
43
43
44
type mockDDLPuller struct {
44
45
// DDLPuller
46
+ << << << < HEAD
45
47
resolvedTs model.Ts
46
48
ddlQueue []* timodel.Job
47
49
}
@@ -51,6 +53,12 @@ func (m *mockDDLPuller) FrontDDL() (uint64, *timodel.Job) {
51
53
return m .ddlQueue [0 ].BinlogInfo .FinishedTS , m .ddlQueue [0 ]
52
54
}
53
55
return m .resolvedTs , nil
56
+ == == == =
57
+ resolvedTs model .Ts
58
+ ddlQueue []* timodel.Job
59
+ schemaStorage entry .SchemaStorage
60
+ closed int64
61
+ >> >> >> > b949fa6674 (chann (ticdc ): fix a panic that send on closed channel (#12245 ))
54
62
}
55
63
56
64
func (m * mockDDLPuller ) PopFrontDDL () (uint64 , * timodel.Job ) {
@@ -62,7 +70,11 @@ func (m *mockDDLPuller) PopFrontDDL() (uint64, *timodel.Job) {
62
70
return m .resolvedTs , nil
63
71
}
64
72
65
- func (m * mockDDLPuller ) Close () {}
73
+ func (m * mockDDLPuller ) Close () {
74
+ if ! atomic .CompareAndSwapInt64 (& m .closed , 0 , 1 ) {
75
+ panic ("close twice!" )
76
+ }
77
+ }
66
78
67
79
func (m * mockDDLPuller ) Run (ctx cdcContext.Context ) error {
68
80
<- ctx .Done ()
@@ -525,7 +537,13 @@ func testChangefeedReleaseResource(
525
537
redoLogDir string ,
526
538
expectedInitialized bool ,
527
539
) {
540
+ << << << < HEAD
528
541
cf , state , captures , tester := createChangefeed4Test (ctx , t )
542
+ == == == =
543
+ var err error
544
+ cf , captures , tester , state := createChangefeed4Test (globalVars , changefeedInfo , newMockDDLSink , t )
545
+ defer cf .Close (ctx )
546
+ >> >> >> > b949fa6674 (chann (ticdc ): fix a panic that send on closed channel (#12245 ))
529
547
530
548
// pre check
531
549
cf .Tick (ctx , state , captures )
@@ -1050,3 +1068,25 @@ func TestBarrierAdvance(t *testing.T) {
1050
1068
require .Equal (t , mockDDLPuller .resolvedTs , barrier )
1051
1069
}
1052
1070
}
1071
+
1072
+ func TestReleaseResourcesTwice (t * testing.T ) {
1073
+ globalVars , changefeedInfo := vars .NewGlobalVarsAndChangefeedInfo4Test ()
1074
+ ctx := context .Background ()
1075
+ cf , captures , tester , state := createChangefeed4Test (globalVars , changefeedInfo , newMockDDLSink , t )
1076
+ defer cf .Close (ctx )
1077
+
1078
+ // pre check
1079
+ state .CheckCaptureAlive (globalVars .CaptureInfo .ID )
1080
+ require .False (t , preflightCheck (state , captures ))
1081
+ tester .MustApplyPatches ()
1082
+
1083
+ // initialize
1084
+ cf .Tick (ctx , state .Info , state .Status , captures )
1085
+ tester .MustApplyPatches ()
1086
+ require .Equal (t , cf .initialized .Load (), true )
1087
+
1088
+ // close twice
1089
+ cf .releaseResources (ctx )
1090
+ cf .isReleased = false
1091
+ cf .releaseResources (ctx )
1092
+ }
0 commit comments