Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #1756 partial finished #1879

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions cri/stream/request_cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package stream

import (
"testing"
)

// TODO: use fake clock to test gc of request cache.

func TestRequestCacheBasic(t *testing.T) {
var tokens []string
r := NewRequestCache()

for i := 0; i < 10; i++ {
token, err := r.Insert(i)
if err != nil {
t.Fatalf("unexpected error when inserting the request: %v", err)
}
tokens = append(tokens, token)
}

for i := 0; i < 10; i++ {
require, found := r.Consume(tokens[i])
if !found {
t.Fatalf("unexpected error when comsuming the cached request")
}
r, ok := require.(int)
if !ok {
t.Fatalf("the type of cached request has been changed")
}
if r != i {
t.Fatalf("the value of cached request has been changed")
}
}
}

func TestRequestCacheNonExist(t *testing.T) {
r := NewRequestCache()
token := "non-exist"
_, found := r.Consume(token)
if found {
t.Fatalf("should not find the request that not exist")
}
}