-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store/tikv: remove dependency on testkit #22520
Changes from all commits
4348da4
6decba5
c4dc84d
682c67e
470c045
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package store | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"sync" | ||
|
||
. "github.com/pingcap/check" | ||
"github.com/pingcap/errors" | ||
"github.com/pingcap/tidb/kv" | ||
"github.com/pingcap/tidb/store/mockstore/unistore" | ||
"github.com/pingcap/tidb/store/tikv" | ||
) | ||
|
||
var ( | ||
withTiKVGlobalLock sync.RWMutex | ||
WithTiKV = flag.Bool("with-tikv", false, "run tests with TiKV cluster started. (not use the mock server)") | ||
pdAddrs = flag.String("pd-addrs", "127.0.0.1:2379", "pd addrs") | ||
) | ||
|
||
// NewTestStore creates a kv.Storage for testing purpose. | ||
func NewTestStore(c *C) kv.Storage { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's in _test.go file, we cannot import it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we move it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll give it a try. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AndreMouche Looks we cannot do it. The reason is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sad |
||
if !flag.Parsed() { | ||
flag.Parse() | ||
} | ||
|
||
if *WithTiKV { | ||
var d tikv.Driver | ||
store, err := d.Open(fmt.Sprintf("tikv://%s", *pdAddrs)) | ||
c.Assert(err, IsNil) | ||
err = clearStorage(store) | ||
c.Assert(err, IsNil) | ||
return store | ||
} | ||
client, pdClient, cluster, err := unistore.New("") | ||
c.Assert(err, IsNil) | ||
unistore.BootstrapWithSingleStore(cluster) | ||
store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0) | ||
c.Assert(err, IsNil) | ||
return store | ||
} | ||
|
||
func clearStorage(store kv.Storage) error { | ||
txn, err := store.Begin() | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
iter, err := txn.Iter(nil, nil) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
for iter.Valid() { | ||
txn.Delete(iter.Key()) | ||
if err := iter.Next(); err != nil { | ||
return errors.Trace(err) | ||
} | ||
} | ||
return txn.Commit(context.Background()) | ||
} | ||
|
||
// OneByOneSuite is a suite, When with-tikv flag is true, there is only one storage, so the test suite have to run one by one. | ||
type OneByOneSuite struct{} | ||
|
||
func (s *OneByOneSuite) SetUpSuite(c *C) { | ||
if *WithTiKV { | ||
withTiKVGlobalLock.Lock() | ||
} else { | ||
withTiKVGlobalLock.RLock() | ||
} | ||
} | ||
|
||
func (s *OneByOneSuite) TearDownSuite(c *C) { | ||
if *WithTiKV { | ||
withTiKVGlobalLock.Unlock() | ||
} else { | ||
withTiKVGlobalLock.RUnlock() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a little strange to put the coprocessor test file in the /store directly, however, I do not know where would be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree. I think we can consider it later.