"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/scheduler/internal/queue/pod_backoff_test.go" between
kubernetes-1.15.9.tar.gz and kubernetes-1.15.10.tar.gz

About: Kubernetes is a platform for automating deployment, scaling, and operations of application containers across clusters of hosts (written in "Go"). 1.15.x series.

pod_backoff_test.go  (kubernetes-1.15.9):pod_backoff_test.go  (kubernetes-1.15.10)
skipping to change at line 20 skipping to change at line 20
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package queue package queue
import ( import (
"fmt"
"testing" "testing"
"time" "time"
ktypes "k8s.io/apimachinery/pkg/types" ktypes "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/clock"
) )
func TestBackoffPod(t *testing.T) { func TestBackoffPod(t *testing.T) {
bpm := NewPodBackoffMap(1*time.Second, 10*time.Second) timestamp := time.Now()
bpm := NewPodBackoffMap(1*time.Second, 10*time.Second, clock.NewFakeClock
(timestamp))
tests := []struct { tests := []struct {
podID ktypes.NamespacedName podID ktypes.NamespacedName
expectedDuration time.Duration expectedDuration time.Duration
advanceClock time.Duration advanceClock time.Duration
}{ }{
{ {
podID: ktypes.NamespacedName{Namespace: "defau lt", Name: "foo"}, podID: ktypes.NamespacedName{Namespace: "defau lt", Name: "foo"},
expectedDuration: 1 * time.Second, expectedDuration: 1 * time.Second,
}, },
{ {
skipping to change at line 64 skipping to change at line 66
{ {
podID: ktypes.NamespacedName{Namespace: "defau lt", Name: "foo"}, podID: ktypes.NamespacedName{Namespace: "defau lt", Name: "foo"},
expectedDuration: 10 * time.Second, expectedDuration: 10 * time.Second,
}, },
{ {
podID: ktypes.NamespacedName{Namespace: "defau lt", Name: "bar"}, podID: ktypes.NamespacedName{Namespace: "defau lt", Name: "bar"},
expectedDuration: 1 * time.Second, expectedDuration: 1 * time.Second,
}, },
} }
for _, test := range tests { for i, test := range tests {
// Backoff the pod t.Run(fmt.Sprintf("step %d", i), func(t *testing.T) {
bpm.BackoffPod(test.podID) bpm.BackoffPod(test.podID)
// Get backoff duration for the pod backoff, ok := bpm.GetBackoffTime(test.podID)
duration := bpm.calculateBackoffDuration(test.podID) if !ok {
t.Errorf("%v should be backed off", test.podID)
if duration != test.expectedDuration { }
t.Errorf("expected: %s, got %s for pod %s", test.expected duration := backoff.Sub(timestamp)
Duration.String(), duration.String(), test.podID) if duration != test.expectedDuration {
} t.Errorf("expected: %s, got %s for pod %s", test.
expectedDuration.String(), duration.String(), test.podID)
}
})
} }
} }
func TestClearPodBackoff(t *testing.T) { func TestClearPodBackoff(t *testing.T) {
bpm := NewPodBackoffMap(1*time.Second, 60*time.Second) bpm := NewPodBackoffMap(1*time.Second, 60*time.Second, clock.NewFakeClock (time.Now()))
// Clear backoff on an not existed pod // Clear backoff on an not existed pod
bpm.clearPodBackoff(ktypes.NamespacedName{Namespace: "ns", Name: "not-exi sted"}) bpm.clearPodBackoff(ktypes.NamespacedName{Namespace: "ns", Name: "not-exi sted"})
// Backoff twice for pod foo // Backoff twice for pod foo
podID := ktypes.NamespacedName{Namespace: "ns", Name: "foo"} podID := ktypes.NamespacedName{Namespace: "ns", Name: "foo"}
bpm.BackoffPod(podID) bpm.BackoffPod(podID)
bpm.BackoffPod(podID) bpm.BackoffPod(podID)
if duration := bpm.calculateBackoffDuration(podID); duration != 2*time.Se cond { if duration := bpm.calculateBackoffDuration(podID); duration != 2*time.Se cond {
t.Errorf("Expected backoff of 1s for pod %s, got %s", podID, dura tion.String()) t.Errorf("Expected backoff of 1s for pod %s, got %s", podID, dura tion.String())
} }
// Clear backoff for pod foo // Clear backoff for pod foo
 End of changes. 5 change blocks. 
13 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)