Skip to content
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

bugfix: StringSliceEqual should also consider duplicate items in slice #2561

Merged

Conversation

HusterWan
Copy link
Contributor

Signed-off-by: ziren.wzr ziren.wzr@alibaba-inc.com

Ⅰ. Describe what this PR did

When a slice have duplicate items, the StringSliceEqual may get wrong answer

Ⅱ. Does this pull request fix one issue?

fixes: #2560

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

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov
Copy link

codecov bot commented Dec 13, 2018

Codecov Report

Merging #2561 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2561      +/-   ##
==========================================
+ Coverage   69.07%   69.14%   +0.06%     
==========================================
  Files         278      278              
  Lines       18564    18565       +1     
==========================================
+ Hits        12823    12836      +13     
+ Misses       4273     4259      -14     
- Partials     1468     1470       +2
Flag Coverage Δ
#criv1alpha1test 31.29% <0%> (+0.02%) ⬆️
#criv1alpha2test 35.43% <0%> (-0.16%) ⬇️
#integrationtest 40.6% <0%> (-0.03%) ⬇️
#nodee2etest 32.56% <0%> (+0.01%) ⬆️
#unittest 26.83% <100%> (+0.02%) ⬆️
Impacted Files Coverage Δ
pkg/utils/utils.go 84.93% <100%> (+1.9%) ⬆️
daemon/logger/jsonfile/utils.go 71.54% <0%> (-1.63%) ⬇️
cri/v1alpha2/cri_wrapper.go 64.4% <0%> (-1.2%) ⬇️
cri/v1alpha2/cri.go 68.96% <0%> (-0.38%) ⬇️
daemon/mgr/container.go 58.44% <0%> (-0.22%) ⬇️
ctrd/container.go 59.2% <0%> (+1.18%) ⬆️
pkg/streams/utils.go 89.28% <0%> (+7.14%) ⬆️
cri/ocicni/cni_manager.go 70.58% <0%> (+11.76%) ⬆️

@pouchrobot pouchrobot added kind/bug This is bug report for project size/S labels Dec 13, 2018
@HusterWan HusterWan force-pushed the zr/fix-string-slice-equal branch from 1da79a5 to 37461f8 Compare December 13, 2018 12:01
@@ -306,6 +306,7 @@ func IsFileExist(file string) bool {
}

// StringSliceEqual compare two string slice, ignore the order.
// we also should consider if there has duplicate items in slice.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see here you are describing the case. But for fixing a bug, we should describe the functionality it provides. Maybe you can update the comment about when this function returns true precisely. @HusterWan

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated


// second list all items in s2
for _, v := range s2 {
mapKeys[v]--
Copy link
Contributor

Choose a reason for hiding this comment

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

embedded check here for more efficient

mapKeys[v]--
if mapKeys[v] < 0 {
return false
}

This check covers two situations

  1. if the key is not exists, mapKey[v] == -1
  2. if the key is redundant, mapKey[v] < 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good advice

Copy link
Collaborator

Choose a reason for hiding this comment

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

you are so talented. @zhuangqh 👍 🦁 🐸 🐼

@HusterWan HusterWan force-pushed the zr/fix-string-slice-equal branch 3 times, most recently from 9bc7972 to b08a818 Compare December 14, 2018 06:44
Signed-off-by: ziren.wzr <ziren.wzr@alibaba-inc.com>
@HusterWan HusterWan force-pushed the zr/fix-string-slice-equal branch from b08a818 to fd23316 Compare December 14, 2018 09:40
Copy link
Contributor

@zhuangqh zhuangqh left a comment

Choose a reason for hiding this comment

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

cool👍 LGTM

@zhuangqh zhuangqh merged commit e99d1f8 into AliyunContainerService:master Dec 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is bug report for project size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: StringSliceEqual is wrong
4 participants