Merge pull request #64369 from idealhack/sub-benchmarks/apiserver/aes

Automatic merge from submit-queue (batch tested with PRs 64364, 64369, 63819, 64528). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

apiserver: update tests to use sub-benchmarks (aes_test.go)

**What this PR does / why we need it**:

Go 1.7 added the subtest feature which can make table-driven tests much easier to run and debug. Some tests are not using this feature.

Further reading: [Using Subtests and Sub-benchmarks](https://blog.golang.org/subtests)

/kind cleanup

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2018-05-30 22:54:08 -07:00 committed by GitHub
commit 483b6a6264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -149,14 +149,41 @@ func TestCBCKeyRotation(t *testing.T) {
} }
} }
func BenchmarkGCMRead_16_1024(b *testing.B) { benchmarkGCMRead(b, 16, 1024, false) } func BenchmarkGCMRead(b *testing.B) {
func BenchmarkGCMRead_32_1024(b *testing.B) { benchmarkGCMRead(b, 32, 1024, false) } tests := []struct {
func BenchmarkGCMRead_32_16384(b *testing.B) { benchmarkGCMRead(b, 32, 16384, false) } keyLength int
func BenchmarkGCMRead_32_16384_Stale(b *testing.B) { benchmarkGCMRead(b, 32, 16384, true) } valueLength int
expectStale bool
}{
{keyLength: 16, valueLength: 1024, expectStale: false},
{keyLength: 32, valueLength: 1024, expectStale: false},
{keyLength: 32, valueLength: 16384, expectStale: false},
{keyLength: 32, valueLength: 16384, expectStale: true},
}
for _, t := range tests {
name := fmt.Sprintf("%vKeyLength/%vValueLength/%vExpectStale", t.keyLength, t.valueLength, t.expectStale)
b.Run(name, func(b *testing.B) {
benchmarkGCMRead(b, t.keyLength, t.valueLength, t.expectStale)
})
}
}
func BenchmarkGCMWrite_16_1024(b *testing.B) { benchmarkGCMWrite(b, 16, 1024) } func BenchmarkGCMWrite(b *testing.B) {
func BenchmarkGCMWrite_32_1024(b *testing.B) { benchmarkGCMWrite(b, 32, 1024) } tests := []struct {
func BenchmarkGCMWrite_32_16384(b *testing.B) { benchmarkGCMWrite(b, 32, 16384) } keyLength int
valueLength int
}{
{keyLength: 16, valueLength: 1024},
{keyLength: 32, valueLength: 1024},
{keyLength: 32, valueLength: 16384},
}
for _, t := range tests {
name := fmt.Sprintf("%vKeyLength/%vValueLength", t.keyLength, t.valueLength)
b.Run(name, func(b *testing.B) {
benchmarkGCMWrite(b, t.keyLength, t.valueLength)
})
}
}
func benchmarkGCMRead(b *testing.B, keyLength int, valueLength int, expectStale bool) { func benchmarkGCMRead(b *testing.B, keyLength int, valueLength int, expectStale bool) {
block1, err := aes.NewCipher(bytes.Repeat([]byte("a"), keyLength)) block1, err := aes.NewCipher(bytes.Repeat([]byte("a"), keyLength))
@ -227,12 +254,39 @@ func benchmarkGCMWrite(b *testing.B, keyLength int, valueLength int) {
b.StopTimer() b.StopTimer()
} }
func BenchmarkCBCRead_32_1024(b *testing.B) { benchmarkCBCRead(b, 32, 1024, false) } func BenchmarkCBCRead(b *testing.B) {
func BenchmarkCBCRead_32_16384(b *testing.B) { benchmarkCBCRead(b, 32, 16384, false) } tests := []struct {
func BenchmarkCBCRead_32_16384_Stale(b *testing.B) { benchmarkCBCRead(b, 32, 16384, true) } keyLength int
valueLength int
expectStale bool
}{
{keyLength: 32, valueLength: 1024, expectStale: false},
{keyLength: 32, valueLength: 16384, expectStale: false},
{keyLength: 32, valueLength: 16384, expectStale: true},
}
for _, t := range tests {
name := fmt.Sprintf("%vKeyLength/%vValueLength/%vExpectStale", t.keyLength, t.valueLength, t.expectStale)
b.Run(name, func(b *testing.B) {
benchmarkCBCRead(b, t.keyLength, t.valueLength, t.expectStale)
})
}
}
func BenchmarkCBCWrite_32_1024(b *testing.B) { benchmarkCBCWrite(b, 32, 1024) } func BenchmarkCBCWrite(b *testing.B) {
func BenchmarkCBCWrite_32_16384(b *testing.B) { benchmarkCBCWrite(b, 32, 16384) } tests := []struct {
keyLength int
valueLength int
}{
{keyLength: 32, valueLength: 1024},
{keyLength: 32, valueLength: 16384},
}
for _, t := range tests {
name := fmt.Sprintf("%vKeyLength/%vValueLength", t.keyLength, t.valueLength)
b.Run(name, func(b *testing.B) {
benchmarkCBCWrite(b, t.keyLength, t.valueLength)
})
}
}
func benchmarkCBCRead(b *testing.B, keyLength int, valueLength int, expectStale bool) { func benchmarkCBCRead(b *testing.B, keyLength int, valueLength int, expectStale bool) {
block1, err := aes.NewCipher(bytes.Repeat([]byte("a"), keyLength)) block1, err := aes.NewCipher(bytes.Repeat([]byte("a"), keyLength))