blob: c400c97ee995b57ab6bfa39d669a9c6ad9b74383 [file] [log] [blame]
Colin Crossb98d3bc2019-03-21 16:02:58 -07001// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package status
16
17import (
18 "io/ioutil"
19 "os"
20 "path/filepath"
21 "testing"
22 "time"
23
24 "android/soong/ui/logger"
25)
26
27// Tests that closing the ninja reader when nothing has opened the other end of the fifo is fast.
28func TestNinjaReader_Close(t *testing.T) {
29 tempDir, err := ioutil.TempDir("", "ninja_test")
30 if err != nil {
31 t.Fatal(err)
32 }
33 defer os.RemoveAll(tempDir)
34
35 stat := &Status{}
36 nr := NewNinjaReader(logger.New(ioutil.Discard), stat.StartTool(), filepath.Join(tempDir, "fifo"))
37
38 start := time.Now()
39
40 nr.Close()
41
42 if g, w := time.Since(start), NINJA_READER_CLOSE_TIMEOUT; g >= w {
43 t.Errorf("nr.Close timed out, %s > %s", g, w)
44 }
45}