This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
add dumpling unit test #1115
Merged
Merged
add dumpling unit test #1115
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1bacb2d
add dumpling unit test
GMHDBJD 6fd5aac
address comment
GMHDBJD b453a73
Merge branch 'master' into utDumpling
GMHDBJD dc024e8
address comment
GMHDBJD 753b373
debug ci
GMHDBJD 410b775
debug ci
GMHDBJD decf22c
Merge branch 'master' into utDumpling
GMHDBJD 7fc54dc
address comment
GMHDBJD 88bb2ad
Merge branch 'master' into utDumpling
GMHDBJD 4650445
address comment
GMHDBJD bff9d70
remove commentf
GMHDBJD 99d3a82
Merge branch 'master' into utDumpling
GMHDBJD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2020 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 dumpling | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/pingcap/dm/dm/config" | ||
"github.com/pingcap/dm/dm/pb" | ||
"github.com/pingcap/dm/pkg/log" | ||
"github.com/pingcap/failpoint" | ||
|
||
. "github.com/pingcap/check" | ||
) | ||
|
||
var _ = Suite(&testDumplingSuite{}) | ||
|
||
func TestSuite(t *testing.T) { | ||
TestingT(t) | ||
} | ||
|
||
type testDumplingSuite struct { | ||
cfg *config.SubTaskConfig | ||
} | ||
|
||
func getDBConfigFromEnv() config.DBConfig { | ||
host := os.Getenv("MYSQL_HOST") | ||
if host == "" { | ||
host = "127.0.0.1" | ||
} | ||
port, _ := strconv.Atoi(os.Getenv("MYSQL_PORT")) | ||
if port == 0 { | ||
port = 3306 | ||
} | ||
user := os.Getenv("MYSQL_USER") | ||
if user == "" { | ||
user = "root" | ||
} | ||
pswd := os.Getenv("MYSQL_PSWD") | ||
return config.DBConfig{ | ||
Host: host, | ||
User: user, | ||
Password: pswd, | ||
Port: port, | ||
} | ||
} | ||
|
||
func (d *testDumplingSuite) SetUpSuite(c *C) { | ||
dir := c.MkDir() | ||
d.cfg = &config.SubTaskConfig{ | ||
Name: "dumpling_ut", | ||
From: getDBConfigFromEnv(), | ||
LoaderConfig: config.LoaderConfig{ | ||
Dir: dir, | ||
}, | ||
} | ||
c.Assert(log.InitLogger(&log.Config{}), IsNil) | ||
} | ||
|
||
func (d *testDumplingSuite) TestDumpling(c *C) { | ||
dumpling := NewDumpling(d.cfg) | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
err := dumpling.Init(ctx) | ||
c.Assert(err, IsNil) | ||
resultCh := make(chan pb.ProcessResult, 1) | ||
|
||
dumpling.Process(ctx, resultCh) | ||
c.Assert(len(resultCh), Equals, 1) | ||
result := <-resultCh | ||
c.Assert(result.IsCanceled, IsFalse) | ||
c.Assert(len(result.Errors), Equals, 0, Commentf("errors: %v", result.Errors)) | ||
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. don't forget to remove this |
||
|
||
c.Assert(failpoint.Enable("github.com/pingcap/dm/dumpling/dumpUnitProcessWithError", `return("unknown error")`), IsNil) | ||
// nolint:errcheck | ||
defer failpoint.Disable("github.com/pingcap/dm/dumpling/dumpUnitProcessWithError") | ||
|
||
// return error | ||
dumpling.Process(ctx, resultCh) | ||
c.Assert(len(resultCh), Equals, 1) | ||
result = <-resultCh | ||
c.Assert(result.IsCanceled, IsFalse) | ||
c.Assert(len(result.Errors), Equals, 1) | ||
c.Assert(result.Errors[0].Message, Equals, "unknown error") | ||
|
||
// nolint:errcheck | ||
failpoint.Disable("github.com/pingcap/dm/dumpling/dumpUnitProcessWithError") | ||
|
||
c.Assert(failpoint.Enable("github.com/pingcap/dm/dumpling/dumpUnitProcessCancel", `return("unknown error")`), IsNil) | ||
// nolint:errcheck | ||
defer failpoint.Disable("github.com/pingcap/dm/dumpling/dumpUnitProcessCancel") | ||
|
||
// cancel | ||
dumpling.Process(ctx, resultCh) | ||
c.Assert(len(resultCh), Equals, 1) | ||
result = <-resultCh | ||
c.Assert(result.IsCanceled, IsTrue) | ||
c.Assert(len(result.Errors), Equals, 1) | ||
c.Assert(result.Errors[0].String(), Matches, ".*context deadline exceeded.*") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
how about only use
WithTimeout
in thirddumpling.Process
, I'm afraid when CI runs slowly it will fail