@@ -29,6 +29,7 @@ import (
29
29
"github.com/pingcap/tidb/owner"
30
30
"github.com/pingcap/tidb/parser/terror"
31
31
"github.com/pingcap/tidb/store/mockstore"
32
+ "github.com/pingcap/tidb/testkit"
32
33
"github.com/pingcap/tidb/util/logutil"
33
34
"github.com/stretchr/testify/require"
34
35
clientv3 "go.etcd.io/etcd/client/v3"
@@ -176,6 +177,35 @@ func TestSetAndGetOwnerOpValue(t *testing.T) {
176
177
require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/owner/MockDelOwnerKey" ))
177
178
}
178
179
180
+ // TestGetOwnerOpValueBeforeSet tests get owner opValue before set this value when the etcdClient is nil.
181
+ func TestGetOwnerOpValueBeforeSet (t * testing.T ) {
182
+ if runtime .GOOS == "windows" {
183
+ t .Skip ("integration.NewClusterV3 will create file contains a colon which is not allowed on Windows" )
184
+ }
185
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/owner/MockNotSetOwnerOp" , `return(true)` ))
186
+
187
+ _ , dom := testkit .CreateMockStoreAndDomain (t )
188
+ ddl := dom .DDL ()
189
+ require .NoError (t , ddl .OwnerManager ().CampaignOwner ())
190
+ isOwner := checkOwner (ddl , true )
191
+ require .True (t , isOwner )
192
+
193
+ // test set/get owner info
194
+ manager := ddl .OwnerManager ()
195
+ ownerID , err := manager .GetOwnerID (context .Background ())
196
+ require .NoError (t , err )
197
+ require .Equal (t , ddl .GetID (), ownerID )
198
+ op , err := owner .GetOwnerOpValue (context .Background (), nil , DDLOwnerKey , "log prefix" )
199
+ require .NoError (t , err )
200
+ require .Equal (t , op , owner .OpNone )
201
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/owner/MockNotSetOwnerOp" ))
202
+ err = manager .SetOwnerOpValue (context .Background (), owner .OpGetUpgradingState )
203
+ require .NoError (t , err )
204
+ op , err = owner .GetOwnerOpValue (context .Background (), nil , DDLOwnerKey , "log prefix" )
205
+ require .NoError (t , err )
206
+ require .Equal (t , op , owner .OpGetUpgradingState )
207
+ }
208
+
179
209
func TestCluster (t * testing.T ) {
180
210
if runtime .GOOS == "windows" {
181
211
t .Skip ("integration.NewClusterV3 will create file contains a colon which is not allowed on Windows" )
0 commit comments