Debian Codegraph @

fs/layer/layer_test.go

raw
1 /*
2 Copyright The containerd Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 /*
18 Copyright 2019 The Go Authors. All rights reserved.
19 Use of this source code is governed by a BSD-style
20 license that can be found in the NOTICE.md file.
21 */
22
23 package layer
24
25 import (
26 "testing"
27 "time"
28
29 memorymetadata "github.com/containerd/stargz-snapshotter/metadata/memory"
30 )
31
32 func TestLayer(t *testing.T) {
33 TestSuiteLayer(t, memorymetadata.NewReader)
34 }
35
36 func TestWaiter(t *testing.T) {
37 var (
38 w = newWaiter()
39 waitTime = time.Second
40 startTime = time.Now()
41 doneTime time.Time
42 done = make(chan struct{})
43 )
44
45 go func() {
46 defer close(done)
47 if err := w.wait(10 * time.Second); err != nil {
48 t.Errorf("failed to wait: %v", err)
49 return
50 }
51 doneTime = time.Now()
52 }()
53
54 time.Sleep(waitTime)
55 w.done()
56 <-done
57
58 if doneTime.Sub(startTime) < waitTime {
59 t.Errorf("wait time is too short: %v; want %v", doneTime.Sub(startTime), waitTime)
60 }
61 }