improve ut case for package gcache/gpool (#2290)

* improve ut case for package gcache/gpool

* up
This commit is contained in:
John Guo 2022-11-12 10:49:48 +08:00 committed by GitHub
parent b84034b667
commit 7d1a508ea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 7 deletions

View File

@ -179,6 +179,6 @@ func ExamplePool_Close() {
// wait for pool close // wait for pool close
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
// Output: // May Output:
// Close The Pool // Close The Pool
} }

View File

@ -172,6 +172,7 @@ func TestCache_LRU(t *testing.T) {
v, _ := cache.Get(ctx, 6) v, _ := cache.Get(ctx, 6)
t.Assert(v, 6) t.Assert(v, 6)
time.Sleep(4 * time.Second) time.Sleep(4 * time.Second)
g.Log().Debugf(ctx, `items after lru: %+v`, cache.MustData(ctx))
n, _ = cache.Size(ctx) n, _ = cache.Size(ctx)
t.Assert(n, 2) t.Assert(n, 2)
v, _ = cache.Get(ctx, 6) v, _ = cache.Get(ctx, 6)

View File

@ -17,13 +17,14 @@ func IsSubDomain(subDomain string, mainDomain string) bool {
if p := strings.IndexByte(mainDomain, ':'); p != -1 { if p := strings.IndexByte(mainDomain, ':'); p != -1 {
mainDomain = mainDomain[0:p] mainDomain = mainDomain[0:p]
} }
subArray := strings.Split(subDomain, ".") var (
mainArray := strings.Split(mainDomain, ".") subArray = strings.Split(subDomain, ".")
subLength := len(subArray) mainArray = strings.Split(mainDomain, ".")
mainLength := len(mainArray) subLength = len(subArray)
mainLength = len(mainArray)
)
// Eg: // Eg:
// goframe.org is not sub-dome of 's.goframe.org' // "goframe.org" is not sub-domain of "s.goframe.org".
if mainLength > subLength { if mainLength > subLength {
for i := range mainArray[0 : mainLength-subLength] { for i := range mainArray[0 : mainLength-subLength] {
if mainArray[i] != "*" { if mainArray[i] != "*" {