-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[BEAM-14546] Fix errant pass for empty collections in Count #17813
Changes from all commits
d8d897e
9e986e7
5f685f1
325dd8b
54032c3
b3955fc
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 |
---|---|---|
|
@@ -22,24 +22,62 @@ import ( | |
"github.com/apache/beam/sdks/v2/go/pkg/beam/testing/ptest" | ||
) | ||
|
||
func TestCount_Good(t *testing.T) { | ||
p, s := beam.NewPipelineWithRoot() | ||
col := beam.Create(s, "a", "b", "c", "d", "e") | ||
count := 5 | ||
func TestCount(t *testing.T) { | ||
var tests = []struct { | ||
name string | ||
elements []string | ||
count int | ||
}{ | ||
{ | ||
"full", | ||
[]string{"a", "b", "c", "d", "e"}, | ||
5, | ||
}, | ||
{ | ||
"empty", | ||
[]string{}, | ||
0, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
p, s := beam.NewPipelineWithRoot() | ||
col := beam.CreateList(s, test.elements) | ||
|
||
Count(s, col, "TestCount_Good", count) | ||
if err := ptest.Run(p); err != nil { | ||
t.Errorf("Pipeline failed: %v", err) | ||
Count(s, col, test.name, test.count) | ||
if err := ptest.Run(p); err != nil { | ||
t.Errorf("Pipeline failed: %v", err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestCount_Bad(t *testing.T) { | ||
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. Can we simplify and combine these tests into 1 by adding a 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. We could, although I don't see too much value in bundling them into one suite. The setup isn't particularly long or complicated to test the function, so deduplicating it doesn't add much value IMO. Totally cool doing it if you feel strongly though. 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'd argue its worth doing since more/duplicated code => more opportunities for bugs to slip in when updates are needed and more for a future developer (maybe us) to understand (code is a liability). I'm not going to block on it though, its not very important |
||
p, s := beam.NewPipelineWithRoot() | ||
col := beam.Create(s, "a", "b", "c", "d", "e") | ||
count := 10 | ||
var tests = []struct { | ||
name string | ||
elements []string | ||
count int | ||
}{ | ||
{ | ||
"mismatch", | ||
[]string{"a", "b", "c", "d", "e"}, | ||
10, | ||
}, | ||
{ | ||
"empty pcollection", | ||
[]string{}, | ||
5, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
p, s := beam.NewPipelineWithRoot() | ||
col := beam.CreateList(s, test.elements) | ||
|
||
Count(s, col, "TestCount_Bad", count) | ||
if err := ptest.Run(p); err == nil { | ||
t.Errorf("pipeline SUCCEEDED but should have failed") | ||
Count(s, col, test.name, test.count) | ||
if err := ptest.Run(p); err == nil { | ||
t.Errorf("pipeline SUCCEEDED but should have failed") | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You 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, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package passert | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/apache/beam/sdks/v2/go/pkg/beam" | ||
"github.com/apache/beam/sdks/v2/go/pkg/beam/testing/ptest" | ||
) | ||
|
||
func TestHash_Bad(t *testing.T) { | ||
p, s := beam.NewPipelineWithRoot() | ||
col := beam.CreateList(s, []string{}) | ||
|
||
Hash(s, col, "empty collection", "", 0) | ||
if err := ptest.Run(p); err == nil { | ||
t.Errorf("pipeline SUCCEEDED but should have failed") | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Do we need to add the same thing to Hash and Sum? I think an empty pcollection would silently pass for both of those as well
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.
Sum did need it, confirmed via unit test. Will add some short validation for Hash
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.
Added a small "fail on empty" check for Hash.