Skip to content

Commit f167c3b

Browse files
Initial import
0 parents  commit f167c3b

File tree

10 files changed

+347
-0
lines changed

10 files changed

+347
-0
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export GOPATH=$PWD

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/vendor/**/*
2+
pkg/
3+
.idea/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package core_test
2+
3+
import (
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
6+
7+
"testing"
8+
)
9+
10+
func TestCore(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "Core Suite")
13+
}

src/progress/core/hangs.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package core
2+
3+
import (
4+
"strings"
5+
"fmt"
6+
)
7+
8+
type ProgressHangs struct {
9+
tests map[string]string
10+
startTime *string
11+
endTime *string
12+
}
13+
14+
func NewProgressHangs() *ProgressHangs {
15+
ph := &ProgressHangs{}
16+
ph.tests = make(map[string]string)
17+
return ph
18+
}
19+
20+
func (this *ProgressHangs) ProcessLine(line string) {
21+
parts := strings.Split(line, " ")
22+
if len(parts) < 7 {
23+
return
24+
}
25+
26+
timeStamp := fmt.Sprintf("%s %s %s", parts[0], parts[1], parts[2])
27+
this.endTime = &timeStamp
28+
29+
testName := fmt.Sprintf("%s %s", parts[5], parts[6])
30+
state := parts[3]
31+
32+
if state == "Starting" {
33+
this.tests[testName] = timeStamp
34+
35+
if this.startTime == nil {
36+
this.startTime = &timeStamp
37+
}
38+
} else if state == "Completed" {
39+
delete(this.tests, testName)
40+
}
41+
}
42+
43+
func (this *ProgressHangs) Results() {
44+
fmt.Printf("Started @ %s\n", *this.startTime)
45+
for k, v := range this.tests {
46+
fmt.Printf("%s %s\n", v, k)
47+
}
48+
fmt.Printf("Ended @ %s\n", *this.endTime)
49+
50+
}
51+

src/progress/core/progress.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package core
2+
3+
type Progress interface {
4+
ProcessLine(string)
5+
Results()
6+
}

src/progress/core/timings.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package core
2+
3+
import (
4+
"strings"
5+
"fmt"
6+
"time"
7+
"log"
8+
"sort"
9+
)
10+
11+
type oneTest struct {
12+
TestClass string
13+
StartTime time.Time
14+
EndTime time.Time
15+
Duration time.Duration
16+
TestCount int
17+
}
18+
19+
type ProgressTimings []*oneTest
20+
21+
func NewProgressTimings() *ProgressTimings {
22+
return &ProgressTimings{}
23+
}
24+
25+
// 2017-11-19 15:31:34.493 +0000 Starting test org....
26+
func (this *ProgressTimings) ProcessLine(line string) {
27+
parts := strings.Split(line, " ")
28+
if len(parts) < 7 {
29+
return
30+
}
31+
32+
timeStampRaw := fmt.Sprintf("%s %s %s", parts[0], parts[1], parts[2])
33+
34+
timeStamp, err := time.Parse("2006-01-02 15:04:05.000 -0700", timeStampRaw)
35+
if err != nil {
36+
log.Panicf("Unable to process timestamp %s", timeStampRaw)
37+
}
38+
39+
testClass := parts[5]
40+
state := parts[3]
41+
42+
entry, found := this.get(testClass)
43+
if state == "Starting" {
44+
if found {
45+
entry.StartTime = timeStamp
46+
entry.TestCount += 1
47+
} else {
48+
*this = append(*this, &oneTest{
49+
TestClass: testClass,
50+
StartTime: timeStamp,
51+
TestCount: 1,
52+
})
53+
}
54+
} else if state == "Completed" {
55+
if !found {
56+
log.Panicf("Unable to find entry for %s", testClass)
57+
}
58+
entry.EndTime = timeStamp
59+
entry.Duration += entry.EndTime.Sub(entry.StartTime)
60+
}
61+
}
62+
63+
func (this *ProgressTimings) Results() {
64+
sort.Sort(this)
65+
for _, v := range *this {
66+
fmt.Printf("%9.3f %3d %s\n", v.Duration.Seconds(), v.TestCount, v.TestClass)
67+
}
68+
}
69+
70+
func (this *ProgressTimings) Len() int {
71+
return len(*this)
72+
}
73+
74+
func (this *ProgressTimings) Swap(i, j int) {
75+
(*this)[i], (*this)[j] = (*this)[j], (*this)[i]
76+
}
77+
78+
func (this *ProgressTimings) Less(i, j int) bool {
79+
return (*this)[i].Duration.Nanoseconds() > (*this)[j].Duration.Nanoseconds()
80+
}
81+
82+
func (this *ProgressTimings) get(key string) (*oneTest, bool) {
83+
for _, v := range *this {
84+
if v.TestClass == key {
85+
return v, true
86+
}
87+
}
88+
89+
return nil, false;
90+
}

src/progress/core/timings_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package core_test
2+
3+
import (
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
6+
"progress/core"
7+
"time"
8+
"sort"
9+
)
10+
11+
var _ = Describe("", func() {
12+
It("", func() {
13+
p := core.NewProgressTimings()
14+
15+
p.ProcessLine( "2017-11-19 15:31:34.493 +0000 Starting test TestClass testMethod")
16+
17+
Expect(len(*p)).To(Equal(1))
18+
19+
Expect((*p)[0].StartTime).To(BeTemporally("==", time.Date(2017, 11, 19, 15, 31, 34, int((time.Millisecond *493).Nanoseconds()), time.UTC)))
20+
21+
p.ProcessLine("2017-11-19 15:31:35.493 +0000 Completed test TestClass testMethod")
22+
23+
Expect(len(*p)).To(Equal(1))
24+
Expect((*p)[0].Duration).To(Equal(time.Second * 1))
25+
26+
p.ProcessLine("2017-11-19 15:31:36.493 +0000 Starting test TestClass testMethod")
27+
p.ProcessLine("2017-11-19 15:31:37.493 +0000 Completed test TestClass testMethod")
28+
29+
Expect(len(*p)).To(Equal(1))
30+
Expect((*p)[0].Duration).To(Equal(time.Second * 2))
31+
})
32+
33+
It("Sorts", func() {
34+
p := core.NewProgressTimings()
35+
36+
p.ProcessLine("2017-11-19 15:31:34.493 +0000 Starting test TestClass1 testMethod")
37+
p.ProcessLine("2017-11-19 15:31:35.493 +0000 Completed test TestClass1 testMethod")
38+
p.ProcessLine("2017-11-19 15:31:35.493 +0000 Starting test TestClass2 testMethod")
39+
p.ProcessLine("2017-11-19 15:31:37.493 +0000 Completed test TestClass2 testMethod")
40+
41+
Expect(len(*p)).To(Equal(2))
42+
43+
sort.Sort(p)
44+
45+
Expect((*p)[0].TestClass).To(Equal("TestClass2"))
46+
Expect((*p)[0].Duration).To(Equal(time.Second * 2))
47+
Expect((*p)[0].TestCount).To(Equal(1))
48+
Expect((*p)[1].TestClass).To(Equal("TestClass1"))
49+
Expect((*p)[1].Duration).To(Equal(time.Second * 1))
50+
Expect((*p)[1].TestCount).To(Equal(1))
51+
})
52+
53+
It("Accumulate", func() {
54+
p := core.NewProgressTimings()
55+
56+
p.ProcessLine("2017-11-19 15:31:34.000 +0000 Starting test TestClass1 testMethod1")
57+
p.ProcessLine("2017-11-19 15:31:35.000 +0000 Completed test TestClass1 testMethod1")
58+
p.ProcessLine("2017-11-19 15:31:35.000 +0000 Starting test TestClass1 testMethod2")
59+
p.ProcessLine("2017-11-19 15:31:36.100 +0000 Completed test TestClass1 testMethod2")
60+
p.ProcessLine("2017-11-19 15:31:36.100 +0000 Starting test TestClass1 testMethod3")
61+
p.ProcessLine("2017-11-19 15:31:37.200 +0000 Completed test TestClass1 testMethod3")
62+
63+
Expect(len(*p)).To(Equal(1))
64+
Expect((*p)[0].Duration.Seconds()).To(Equal(3.2))
65+
Expect((*p)[0].TestCount).To(Equal(3))
66+
})
67+
})

src/progress/core/uniques.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package core
2+
3+
import (
4+
"strings"
5+
"fmt"
6+
)
7+
8+
type ProgressUniques struct {
9+
tests []string
10+
}
11+
12+
func NewProgressUniques() *ProgressUniques {
13+
t := make([]string, 0)
14+
return &ProgressUniques{tests: t}
15+
}
16+
17+
func (this *ProgressUniques) ProcessLine(line string) {
18+
parts := strings.Split(line, " ")
19+
if len(parts) < 7 {
20+
return
21+
}
22+
23+
testName := parts[5]
24+
state := parts[3]
25+
26+
if state == "Starting" && ! entryExists(this.tests, testName) {
27+
this.tests = append(this.tests, testName)
28+
}
29+
}
30+
31+
func (this *ProgressUniques) Results() {
32+
for _, v := range this.tests {
33+
fmt.Println(v)
34+
}
35+
}
36+
37+
func entryExists(list []string, entry string) bool {
38+
for _, v := range list {
39+
if v == entry {
40+
return true
41+
}
42+
}
43+
return false
44+
}
45+

src/progress/main.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"os"
6+
"bufio"
7+
"io"
8+
"strings"
9+
"progress/core"
10+
)
11+
12+
func main() {
13+
flag.Parse()
14+
15+
var p core.Progress
16+
switch flag.Arg(0) {
17+
case "times":
18+
p = core.NewProgressTimings()
19+
case "unique":
20+
p = core.NewProgressUniques()
21+
case "hang":
22+
p = core.NewProgressHangs()
23+
}
24+
25+
progressFile, err := os.Open(flag.Arg(1))
26+
if err != nil {
27+
panic(err)
28+
}
29+
30+
defer progressFile.Close()
31+
32+
reader := bufio.NewReader(progressFile)
33+
34+
var line string
35+
for {
36+
line, err = reader.ReadString('\n')
37+
line = strings.TrimSpace(line)
38+
39+
p.ProcessLine(line)
40+
41+
if err != nil {
42+
break
43+
}
44+
}
45+
46+
if err != io.EOF {
47+
panic(err)
48+
}
49+
50+
p.Results()
51+
}
52+

src/progress/vendor/vendor.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"comment": "",
3+
"ignore": "test",
4+
"package": [
5+
{
6+
"checksumSHA1": "BsmyRqx3D6A0RmWl/7K8iWe8PMA=",
7+
"path": "github.com/onsi/ginkgo",
8+
"revision": "652e15c9a27e1cec563e065568014f29eecf6bd9",
9+
"revisionTime": "2017-10-30T19:16:46Z"
10+
},
11+
{
12+
"checksumSHA1": "K/+zcF9uhF8ZCTTUGmeBhPRchGU=",
13+
"path": "github.com/onsi/gomega",
14+
"revision": "1eecca0ba8e6f5ea5a431ce21d3aee2af0b4c90b",
15+
"revisionTime": "2017-11-05T03:16:54Z"
16+
}
17+
],
18+
"rootPath": "progress"
19+
}

0 commit comments

Comments
 (0)