From f36a48f1056ae9b5439a6a54734371ce88b15190 Mon Sep 17 00:00:00 2001 From: Inoria-cn Date: Tue, 24 Jul 2018 11:55:22 +0800 Subject: [PATCH] test --- cri/stream/request_cache_test.go | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cri/stream/request_cache_test.go b/cri/stream/request_cache_test.go index 11541cc2b..40e738687 100644 --- a/cri/stream/request_cache_test.go +++ b/cri/stream/request_cache_test.go @@ -1 +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") + } +}