mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
fix golint failures of test/e2e/chaosmonkey
This commit is contained in:
parent
da31c50da1
commit
a6e0614dd9
@ -588,7 +588,6 @@ staging/src/k8s.io/sample-apiserver/pkg/apis/wardle
|
|||||||
staging/src/k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1
|
staging/src/k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1
|
||||||
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/fischer
|
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/fischer
|
||||||
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/flunder
|
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/flunder
|
||||||
test/e2e/chaosmonkey
|
|
||||||
test/e2e/common
|
test/e2e/common
|
||||||
test/e2e/lifecycle/bootstrap
|
test/e2e/lifecycle/bootstrap
|
||||||
test/e2e/scalability
|
test/e2e/scalability
|
||||||
|
@ -16,13 +16,13 @@ limitations under the License.
|
|||||||
|
|
||||||
package chaosmonkey
|
package chaosmonkey
|
||||||
|
|
||||||
import . "github.com/onsi/ginkgo"
|
import "github.com/onsi/ginkgo"
|
||||||
|
|
||||||
// Disruption is the type to construct a chaosmonkey with; see Do for more information.
|
// Disruption is the type to construct a Chaosmonkey with; see Do for more information.
|
||||||
type Disruption func()
|
type Disruption func()
|
||||||
|
|
||||||
// Test is the type to register with a chaosmonkey. A test will run asynchronously across the
|
// Test is the type to register with a Chaosmonkey. A test will run asynchronously across the
|
||||||
// chaosmonkey's Disruption. A Test takes a Semaphore as an argument. It should call sem.Ready()
|
// Chaosmonkey's Disruption. A Test takes a Semaphore as an argument. It should call sem.Ready()
|
||||||
// once it's ready for the disruption to start and should then wait until sem.StopCh (which is a
|
// once it's ready for the disruption to start and should then wait until sem.StopCh (which is a
|
||||||
// <-chan struct{}) is closed, which signals that the disruption is over. It should then clean up
|
// <-chan struct{}) is closed, which signals that the disruption is over. It should then clean up
|
||||||
// and return. See Do and Semaphore for more information.
|
// and return. See Do and Semaphore for more information.
|
||||||
@ -37,30 +37,31 @@ type Interface interface {
|
|||||||
Teardown()
|
Teardown()
|
||||||
}
|
}
|
||||||
|
|
||||||
type chaosmonkey struct {
|
// Chaosmonkey is the type that holds the necessary content for chaosmonkey test
|
||||||
|
type Chaosmonkey struct {
|
||||||
disruption Disruption
|
disruption Disruption
|
||||||
tests []Test
|
tests []Test
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates and returns a chaosmonkey, with which the caller should register Tests and call Do.
|
// New creates and returns a Chaosmonkey, with which the caller should register Tests and call Do.
|
||||||
// See Do for more information.
|
// See Do for more information.
|
||||||
func New(disruption Disruption) *chaosmonkey {
|
func New(disruption Disruption) *Chaosmonkey {
|
||||||
return &chaosmonkey{
|
return &Chaosmonkey{
|
||||||
disruption,
|
disruption,
|
||||||
[]Test{},
|
[]Test{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register registers the given Test with the chaosmonkey, so that the test will run over the
|
// Register registers the given Test with the Chaosmonkey, so that the test will run over the
|
||||||
// Disruption.
|
// Disruption.
|
||||||
func (cm *chaosmonkey) Register(test Test) {
|
func (cm *Chaosmonkey) Register(test Test) {
|
||||||
cm.tests = append(cm.tests, test)
|
cm.tests = append(cm.tests, test)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterInterface registers the given Interface with the chaosmonkey, so the chaosmonkey will
|
// RegisterInterface registers the given Interface with the Chaosmonkey, so the Chaosmonkey will
|
||||||
// call Setup, Test, and Teardown properly. Test can tell that the Disruption is finished when
|
// call Setup, Test, and Teardown properly. Test can tell that the Disruption is finished when
|
||||||
// stopCh is closed.
|
// stopCh is closed.
|
||||||
func (cm *chaosmonkey) RegisterInterface(in Interface) {
|
func (cm *Chaosmonkey) RegisterInterface(in Interface) {
|
||||||
cm.Register(func(sem *Semaphore) {
|
cm.Register(func(sem *Semaphore) {
|
||||||
in.Setup()
|
in.Setup()
|
||||||
sem.Ready()
|
sem.Ready()
|
||||||
@ -70,11 +71,11 @@ func (cm *chaosmonkey) RegisterInterface(in Interface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do performs the Disruption while testing the registered Tests. Once the caller has registered
|
// Do performs the Disruption while testing the registered Tests. Once the caller has registered
|
||||||
// all Tests with the chaosmonkey, they call Do. Do starts each registered test asynchronously and
|
// all Tests with the Chaosmonkey, they call Do. Do starts each registered test asynchronously and
|
||||||
// waits for each test to signal that it is ready by calling sem.Ready(). Do will then do the
|
// waits for each test to signal that it is ready by calling sem.Ready(). Do will then do the
|
||||||
// Disruption, and when it's complete, close sem.StopCh to signal to the registered Tests that the
|
// Disruption, and when it's complete, close sem.StopCh to signal to the registered Tests that the
|
||||||
// Disruption is over, and wait for all Tests to return.
|
// Disruption is over, and wait for all Tests to return.
|
||||||
func (cm *chaosmonkey) Do() {
|
func (cm *Chaosmonkey) Do() {
|
||||||
sems := []*Semaphore{}
|
sems := []*Semaphore{}
|
||||||
// All semaphores have the same StopCh.
|
// All semaphores have the same StopCh.
|
||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
@ -84,13 +85,13 @@ func (cm *chaosmonkey) Do() {
|
|||||||
sem := newSemaphore(stopCh)
|
sem := newSemaphore(stopCh)
|
||||||
sems = append(sems, sem)
|
sems = append(sems, sem)
|
||||||
go func() {
|
go func() {
|
||||||
defer GinkgoRecover()
|
defer ginkgo.GinkgoRecover()
|
||||||
defer sem.done()
|
defer sem.done()
|
||||||
test(sem)
|
test(sem)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
By("Waiting for all async tests to be ready")
|
ginkgo.By("Waiting for all async tests to be ready")
|
||||||
for _, sem := range sems {
|
for _, sem := range sems {
|
||||||
// Wait for test to be ready. We have to wait for ready *or done* because a test
|
// Wait for test to be ready. We have to wait for ready *or done* because a test
|
||||||
// may panic before signaling that its ready, and we shouldn't block. Since we
|
// may panic before signaling that its ready, and we shouldn't block. Since we
|
||||||
@ -100,15 +101,15 @@ func (cm *chaosmonkey) Do() {
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
close(stopCh)
|
close(stopCh)
|
||||||
By("Waiting for async validations to complete")
|
ginkgo.By("Waiting for async validations to complete")
|
||||||
for _, sem := range sems {
|
for _, sem := range sems {
|
||||||
sem.waitForDone()
|
sem.waitForDone()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
By("Starting disruption")
|
ginkgo.By("Starting disruption")
|
||||||
cm.disruption()
|
cm.disruption()
|
||||||
By("Disruption complete; stopping async validations")
|
ginkgo.By("Disruption complete; stopping async validations")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Semaphore is taken by a Test and provides: Ready(), for the Test to call when it's ready for the
|
// Semaphore is taken by a Test and provides: Ready(), for the Test to call when it's ready for the
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestDoWithPanic(t *testing.T) {
|
func TestDoWithPanic(t *testing.T) {
|
||||||
var counter int64 = 0
|
var counter int64
|
||||||
cm := New(func() {})
|
cm := New(func() {})
|
||||||
tests := []Test{
|
tests := []Test{
|
||||||
// No panic
|
// No panic
|
||||||
|
Loading…
Reference in New Issue
Block a user