mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Fix or remove tests that don't work in race mode
This commit is contained in:
parent
2f263b24a7
commit
68bb8b827b
@ -1,95 +0,0 @@
|
|||||||
// +build !race
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2014 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed 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 controlplane
|
|
||||||
|
|
||||||
// This test file is separated from master_test.go so we would be able to disable
|
|
||||||
// race check for it. TestValidOpenAPISpec will became extremely slow if -race
|
|
||||||
// flag exists, and will cause the tests to timeout.
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/go-openapi/loads"
|
|
||||||
"github.com/go-openapi/spec"
|
|
||||||
"github.com/go-openapi/strfmt"
|
|
||||||
"github.com/go-openapi/validate"
|
|
||||||
openapinamer "k8s.io/apiserver/pkg/endpoints/openapi"
|
|
||||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
|
||||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
|
||||||
openapigen "k8s.io/kubernetes/pkg/generated/openapi"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestValidOpenAPISpec verifies that the open api is added
|
|
||||||
// at the proper endpoint and the spec is valid.
|
|
||||||
func TestValidOpenAPISpec(t *testing.T) {
|
|
||||||
etcdserver, config, assert := setUp(t)
|
|
||||||
defer etcdserver.Terminate(t)
|
|
||||||
|
|
||||||
config.GenericConfig.EnableIndex = true
|
|
||||||
config.GenericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(openapigen.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(legacyscheme.Scheme))
|
|
||||||
config.GenericConfig.OpenAPIConfig.Info = &spec.Info{
|
|
||||||
InfoProps: spec.InfoProps{
|
|
||||||
Title: "Kubernetes",
|
|
||||||
Version: "unversioned",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
master, err := config.Complete().New(genericapiserver.NewEmptyDelegate())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Error in bringing up the master: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure swagger.json is not registered before calling PrepareRun.
|
|
||||||
server := httptest.NewServer(master.GenericAPIServer.Handler.Director)
|
|
||||||
defer server.Close()
|
|
||||||
resp, err := http.Get(server.URL + "/openapi/v2")
|
|
||||||
if !assert.NoError(err) {
|
|
||||||
t.Errorf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
assert.Equal(http.StatusNotFound, resp.StatusCode)
|
|
||||||
|
|
||||||
master.GenericAPIServer.PrepareRun()
|
|
||||||
|
|
||||||
resp, err = http.Get(server.URL + "/openapi/v2")
|
|
||||||
if !assert.NoError(err) {
|
|
||||||
t.Errorf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
assert.Equal(http.StatusOK, resp.StatusCode)
|
|
||||||
|
|
||||||
// as json schema
|
|
||||||
var sch spec.Schema
|
|
||||||
if assert.NoError(decodeResponse(resp, &sch)) {
|
|
||||||
validator := validate.NewSchemaValidator(spec.MustLoadSwagger20Schema(), nil, "", strfmt.Default)
|
|
||||||
res := validator.Validate(&sch)
|
|
||||||
assert.NoError(res.AsError())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate OpenApi spec
|
|
||||||
doc, err := loads.Spec(server.URL + "/openapi/v2")
|
|
||||||
if assert.NoError(err) {
|
|
||||||
validator := validate.NewSpecValidator(doc.Schema(), strfmt.Default)
|
|
||||||
res, warns := validator.Validate(doc)
|
|
||||||
assert.NoError(res.AsError())
|
|
||||||
if !warns.IsValid() {
|
|
||||||
t.Logf("Open API spec on root has some warnings : %v", warns)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,3 @@
|
|||||||
// +build !race
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2016 The Kubernetes Authors.
|
Copyright 2016 The Kubernetes Authors.
|
||||||
|
|
||||||
@ -25,6 +23,7 @@ import (
|
|||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,33 +45,30 @@ func TestMutationDetector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
defer close(stopCh)
|
defer close(stopCh)
|
||||||
addReceived := make(chan bool)
|
|
||||||
mutationFound := make(chan bool)
|
mutationFound := make(chan bool)
|
||||||
|
|
||||||
informer := NewSharedInformer(lw, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer)
|
informer := NewSharedInformer(lw, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer)
|
||||||
informer.cacheMutationDetector = &defaultCacheMutationDetector{
|
detector := &defaultCacheMutationDetector{
|
||||||
name: "name",
|
name: "name",
|
||||||
period: 1 * time.Second,
|
period: 1 * time.Second,
|
||||||
failureFunc: func(message string) {
|
failureFunc: func(message string) {
|
||||||
mutationFound <- true
|
mutationFound <- true
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
informer.AddEventHandler(
|
informer.cacheMutationDetector = detector
|
||||||
ResourceEventHandlerFuncs{
|
|
||||||
AddFunc: func(obj interface{}) {
|
|
||||||
addReceived <- true
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
go informer.Run(stopCh)
|
go informer.Run(stopCh)
|
||||||
|
|
||||||
fakeWatch.Add(pod)
|
fakeWatch.Add(pod)
|
||||||
|
|
||||||
select {
|
wait.PollImmediate(100*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
|
||||||
case <-addReceived:
|
detector.addedObjsLock.Lock()
|
||||||
}
|
defer detector.addedObjsLock.Unlock()
|
||||||
|
return len(detector.addedObjs) > 0, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
detector.compareObjectsLock.Lock()
|
||||||
pod.Labels["change"] = "true"
|
pod.Labels["change"] = "true"
|
||||||
|
detector.compareObjectsLock.Unlock()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-mutationFound:
|
case <-mutationFound:
|
||||||
|
Loading…
Reference in New Issue
Block a user