Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Add unit test cases for download_api_test.go&algorithm_test.go&atomiccount_test.go&httpuils_test.go #1272

Merged
merged 1 commit into from
May 13, 2020

Conversation

zouy414
Copy link
Contributor

@zouy414 zouy414 commented Apr 9, 2020

Signed-off-by: ZouYu [email protected]

Ⅰ. Describe what this PR did

Add unit test case

Ⅱ. Does this pull request fix one issue?

NONE

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

NONE

Ⅳ. Describe how to verify it

NONE

Ⅴ. Special notes for reviews

NONE

@codecov-io
Copy link

codecov-io commented Apr 9, 2020

Codecov Report

Merging #1272 into master will increase coverage by 0.21%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1272      +/-   ##
==========================================
+ Coverage   48.75%   48.97%   +0.21%     
==========================================
  Files         119      119              
  Lines        7763     7763              
==========================================
+ Hits         3785     3802      +17     
+ Misses       3663     3649      -14     
+ Partials      315      312       -3     
Impacted Files Coverage Δ
dfget/core/api/download_api.go 30.23% <0.00%> (+4.65%) ⬆️
client/httputils.go 48.93% <0.00%> (+8.51%) ⬆️
pkg/atomiccount/atomiccount.go 100.00% <0.00%> (+15.38%) ⬆️
dfget/util/algorithm.go 100.00% <0.00%> (+34.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d28168...bbb4634. Read the comment docs.

@zouy414 zouy414 changed the title Add unit test case for dfget/core/api/download_api_test.go Add unit test case Apr 9, 2020
@pouchrobot
Copy link
Collaborator

Thanks for your contribution. 🍻 @Hellcatlk
While we thought PR TITLE could be more specific, longer than 20 chars.
Please edit this PR title instead of opening a new one.
More details, please refer to https://github.com/%!s(MISSING)/%!s(MISSING)/blob/master/CONTRIBUTING.md

@zouy414 zouy414 changed the title Add unit test case Add unit test case for download_api_test.go/algorithm_test.go /atomiccount_test.go/httpuils_test.go Apr 9, 2020
@zouy414 zouy414 changed the title Add unit test case for download_api_test.go/algorithm_test.go /atomiccount_test.go/httpuils_test.go Add unit test cases for download_api_test.go/algorithm_test.go /atomiccount_test.go/httpuils_test.go Apr 9, 2020
@@ -52,4 +52,10 @@ func (s *AlgorithmTestSuite) TestShuffle(c *check.C) {
Shuffle(n, func(i, j int) { isRun++ })
c.Assert(isRun, check.Equals, n-1)
}

Shuffle(1<<31, func(i, j int) {
if 31-1 <= i {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add some description here? I'm not very clear about its meaning of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if i let the loop complete, it will time out.
So i need to make the loop stop early.

Copy link
Contributor Author

@zouy414 zouy414 Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, this is my mistake. It should be 1<<31-1.

@zouy414 zouy414 changed the title Add unit test cases for download_api_test.go/algorithm_test.go /atomiccount_test.go/httpuils_test.go Add unit test cases for download_api_test.go&algorithm_test.go&atomiccount_test.go&httpuils_test.go Apr 16, 2020
@@ -39,6 +39,9 @@ func (suite *AtomicCountUtilSuite) TestAdd(c *check.C) {

result := acount.Get()
c.Check(result, check.Equals, (int32)(12))

var nilAcount *AtomicInt
c.Check(nilAcount.Add(5), check.Equals, (int32)(0))
Copy link
Member

@lowzj lowzj Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes me confused why there is no panic when invoking the function of nil struct pointer. After a while, I understand: nilAcount.Add(5) equals (*AtomicInt).Add(nilAcount, 5) in GoLang, and the implementation of function AtomicInt#Add checks nil pointer before dereference it.

But is it a reasonable implementation?

  • It's rare to check itself in a struct's own function. Why not let it panic directly?
  • The behavior of the AtomicInt functions are inconsistent: Set doesn't check.
  • Any value plus zero value should be equal to itself, but Add returns 0.

@starnop WDYT

@lowzj
Copy link
Member

lowzj commented May 13, 2020

Could you rebase your code and combine your commits into one commit?

@zouy414 zouy414 force-pushed the master branch 2 times, most recently from 31497b2 to 6da8759 Compare May 13, 2020 03:28
@zouy414
Copy link
Contributor Author

zouy414 commented May 13, 2020

@lowzj , Of course. Done.

Signed-off-by: ZouYu <[email protected]>
Copy link
Member

@lowzj lowzj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lowzj lowzj merged commit 164e390 into dragonflyoss:master May 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants