Merge pull request #9177 from bitsf/fix_tag_retention_test

adjust wait job timeout in test case
This commit is contained in:
Ziming 2019-09-23 14:47:05 +08:00 committed by GitHub
commit df625f4ef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 36 deletions

View File

@ -17,12 +17,12 @@ package dayspl
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/stretchr/testify/assert"
"testing" "testing"
"time" "time"
"github.com/goharbor/harbor/src/pkg/art" "github.com/goharbor/harbor/src/pkg/art"
"github.com/goharbor/harbor/src/pkg/retention/policy/rule" "github.com/goharbor/harbor/src/pkg/retention/policy/rule"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )
@ -55,14 +55,14 @@ func (e *EvaluatorTestSuite) TestNew() {
func (e *EvaluatorTestSuite) TestProcess() { func (e *EvaluatorTestSuite) TestProcess() {
now := time.Now().UTC() now := time.Now().UTC()
data := []*art.Candidate{ data := []*art.Candidate{
{PulledTime: daysAgo(now, 1)}, {PulledTime: daysAgo(now, 1, time.Hour)},
{PulledTime: daysAgo(now, 2)}, {PulledTime: daysAgo(now, 2, time.Hour)},
{PulledTime: daysAgo(now, 3)}, {PulledTime: daysAgo(now, 3, time.Hour)},
{PulledTime: daysAgo(now, 4)}, {PulledTime: daysAgo(now, 4, time.Hour)},
{PulledTime: daysAgo(now, 5)}, {PulledTime: daysAgo(now, 5, time.Hour)},
{PulledTime: daysAgo(now, 10)}, {PulledTime: daysAgo(now, 10, time.Hour)},
{PulledTime: daysAgo(now, 20)}, {PulledTime: daysAgo(now, 20, time.Hour)},
{PulledTime: daysAgo(now, 30)}, {PulledTime: daysAgo(now, 30, time.Hour)},
} }
tests := []struct { tests := []struct {
@ -71,13 +71,13 @@ func (e *EvaluatorTestSuite) TestProcess() {
minPullTime int64 minPullTime int64
}{ }{
{n: 0, expected: 0, minPullTime: 0}, {n: 0, expected: 0, minPullTime: 0},
{n: 1, expected: 1, minPullTime: daysAgo(now, 1)}, {n: 1, expected: 1, minPullTime: daysAgo(now, 1, 0)},
{n: 2, expected: 2, minPullTime: daysAgo(now, 2)}, {n: 2, expected: 2, minPullTime: daysAgo(now, 2, 0)},
{n: 3, expected: 3, minPullTime: daysAgo(now, 3)}, {n: 3, expected: 3, minPullTime: daysAgo(now, 3, 0)},
{n: 4, expected: 4, minPullTime: daysAgo(now, 4)}, {n: 4, expected: 4, minPullTime: daysAgo(now, 4, 0)},
{n: 5, expected: 5, minPullTime: daysAgo(now, 5)}, {n: 5, expected: 5, minPullTime: daysAgo(now, 5, 0)},
{n: 15, expected: 6, minPullTime: daysAgo(now, 10)}, {n: 15, expected: 6, minPullTime: daysAgo(now, 10, 0)},
{n: 90, expected: 8, minPullTime: daysAgo(now, 30)}, {n: 90, expected: 8, minPullTime: daysAgo(now, 30, 0)},
} }
for _, tt := range tests { for _, tt := range tests {
@ -120,6 +120,6 @@ func TestEvaluatorSuite(t *testing.T) {
suite.Run(t, &EvaluatorTestSuite{}) suite.Run(t, &EvaluatorTestSuite{})
} }
func daysAgo(from time.Time, n int) int64 { func daysAgo(from time.Time, n int, offset time.Duration) int64 {
return from.Add(time.Duration(-1*24*n) * time.Hour).Unix() return from.Add(time.Duration(-1*24*n)*time.Hour + offset).Unix()
} }

View File

@ -55,14 +55,14 @@ func (e *EvaluatorTestSuite) TestNew() {
func (e *EvaluatorTestSuite) TestProcess() { func (e *EvaluatorTestSuite) TestProcess() {
now := time.Now().UTC() now := time.Now().UTC()
data := []*art.Candidate{ data := []*art.Candidate{
{PushedTime: daysAgo(now, 1)}, {PushedTime: daysAgo(now, 1, time.Hour)},
{PushedTime: daysAgo(now, 2)}, {PushedTime: daysAgo(now, 2, time.Hour)},
{PushedTime: daysAgo(now, 3)}, {PushedTime: daysAgo(now, 3, time.Hour)},
{PushedTime: daysAgo(now, 4)}, {PushedTime: daysAgo(now, 4, time.Hour)},
{PushedTime: daysAgo(now, 5)}, {PushedTime: daysAgo(now, 5, time.Hour)},
{PushedTime: daysAgo(now, 10)}, {PushedTime: daysAgo(now, 10, time.Hour)},
{PushedTime: daysAgo(now, 20)}, {PushedTime: daysAgo(now, 20, time.Hour)},
{PushedTime: daysAgo(now, 30)}, {PushedTime: daysAgo(now, 30, time.Hour)},
} }
tests := []struct { tests := []struct {
@ -71,13 +71,13 @@ func (e *EvaluatorTestSuite) TestProcess() {
minPushTime int64 minPushTime int64
}{ }{
{n: 0, expected: 0, minPushTime: 0}, {n: 0, expected: 0, minPushTime: 0},
{n: 1, expected: 1, minPushTime: daysAgo(now, 1)}, {n: 1, expected: 1, minPushTime: daysAgo(now, 1, 0)},
{n: 2, expected: 2, minPushTime: daysAgo(now, 2)}, {n: 2, expected: 2, minPushTime: daysAgo(now, 2, 0)},
{n: 3, expected: 3, minPushTime: daysAgo(now, 3)}, {n: 3, expected: 3, minPushTime: daysAgo(now, 3, 0)},
{n: 4, expected: 4, minPushTime: daysAgo(now, 4)}, {n: 4, expected: 4, minPushTime: daysAgo(now, 4, 0)},
{n: 5, expected: 5, minPushTime: daysAgo(now, 5)}, {n: 5, expected: 5, minPushTime: daysAgo(now, 5, 0)},
{n: 15, expected: 6, minPushTime: daysAgo(now, 10)}, {n: 15, expected: 6, minPushTime: daysAgo(now, 10, 0)},
{n: 90, expected: 8, minPushTime: daysAgo(now, 30)}, {n: 90, expected: 8, minPushTime: daysAgo(now, 30, 0)},
} }
for _, tt := range tests { for _, tt := range tests {
@ -120,6 +120,6 @@ func TestEvaluatorSuite(t *testing.T) {
suite.Run(t, &EvaluatorTestSuite{}) suite.Run(t, &EvaluatorTestSuite{})
} }
func daysAgo(from time.Time, n int) int64 { func daysAgo(from time.Time, n int, offset time.Duration) int64 {
return from.Add(time.Duration(-1*24*n) * time.Hour).Unix() return from.Add(time.Duration(-1*24*n)*time.Hour + offset).Unix()
} }

View File

@ -70,7 +70,7 @@ class TestProjects(unittest.TestCase):
# Dry run # Dry run
self.retention.trigger_retention_policy(retention_id, dry_run=True, **TestProjects.USER_RA_CLIENT) self.retention.trigger_retention_policy(retention_id, dry_run=True, **TestProjects.USER_RA_CLIENT)
time.sleep(2) time.sleep(10)
resp=self.retention.get_retention_executions(retention_id, **TestProjects.USER_RA_CLIENT) resp=self.retention.get_retention_executions(retention_id, **TestProjects.USER_RA_CLIENT)
self.assertTrue(len(resp)>0) self.assertTrue(len(resp)>0)
execution=resp[0] execution=resp[0]