blob: 6f9411369e10aba3a8354d5d967d565c13334338 [file] [log] [blame]
Shinichiro Hamajib69bf8a2015-06-10 14:52:06 +09001// Copyright 2015 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
Shinichiro Hamajicedc5c82015-05-13 17:03:20 +090015package main
16
17import (
18 "fmt"
19 "path/filepath"
20 "testing"
21)
22
23func TestPara(t *testing.T) {
24 cwd, err := filepath.Abs(".")
25 if err != nil {
26 panic(err)
27 }
28 katiDir = cwd
Shinichiro Hamajia6808422015-05-13 18:00:50 +090029 jobsFlag = 4
Shinichiro Hamajicedc5c82015-05-13 17:03:20 +090030
31 paraChan := make(chan *ParaResult)
32 para := NewParaWorker(paraChan)
33 go para.Run()
34
Fumitoshi Ukai936de102015-06-08 11:21:16 +090035 numTasks := 100
36 for i := 0; i < numTasks; i++ {
Shinichiro Hamajicedc5c82015-05-13 17:03:20 +090037 runners := []runner{
38 {
39 output: fmt.Sprintf("%d", i),
40 cmd: fmt.Sprintf("echo test%d 2>&1", i),
41 shell: "/bin/sh",
42 },
43 }
44 para.RunCommand(runners)
45 }
46
Shinichiro Hamajia6808422015-05-13 18:00:50 +090047 var started []*ParaResult
Shinichiro Hamajicedc5c82015-05-13 17:03:20 +090048 var results []*ParaResult
Fumitoshi Ukai936de102015-06-08 11:21:16 +090049 for len(started) != numTasks || len(results) != numTasks {
Shinichiro Hamajicedc5c82015-05-13 17:03:20 +090050 select {
51 case r := <-paraChan:
Shinichiro Hamajia6808422015-05-13 18:00:50 +090052 fmt.Printf("started=%d finished=%d\n", len(started), len(results))
53 if r.status < 0 && r.signal < 0 {
54 started = append(started, r)
55 } else {
56 results = append(results, r)
57 }
Shinichiro Hamajicedc5c82015-05-13 17:03:20 +090058 }
59 }
60
61 para.Wait()
62}