Skip to content

Commit 9a7736e

Browse files
authored
Fix the missing last few tests for a tarball (#830)
* Update pt.go * add unittest * fix diff * move code
1 parent a45d40c commit 9a7736e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

parser/pt.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,15 @@ func (pt *PTParser) ProcessLastTests() error {
479479
for _, oneTest := range pt.previousTests {
480480
pt.InsertOneTest(oneTest)
481481
}
482+
482483
pt.previousTests = []cachedPTData{}
483484
return nil
484485
}
485486

486487
func (pt *PTParser) Flush() error {
487488
pt.ProcessLastTests()
489+
pt.Annotate(pt.TableName())
490+
pt.Put(pt.TakeRows())
488491
return pt.Inserter.Flush()
489492
}
490493

parser/pt_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,34 @@ func TestPTInserter(t *testing.T) {
271271
}
272272
}
273273

274+
func TestPTInserterLastTest(t *testing.T) {
275+
ins := newInMemoryInserter()
276+
pt := parser.NewPTParser(ins)
277+
rawData, err := ioutil.ReadFile("testdata/PT/20130524T00:04:44Z_ALL5729.paris")
278+
if err != nil {
279+
t.Fatalf("cannot read testdata.")
280+
}
281+
meta := map[string]bigquery.Value{"filename": "gs://fake-bucket/fake-archive.tgz"}
282+
err = pt.ParseAndInsert(meta, "testdata/PT/20130524T00:04:44Z_ALL5729.paris", rawData)
283+
if err != nil {
284+
t.Fatalf(err.Error())
285+
}
286+
287+
if pt.NumRowsForTest() != 0 {
288+
fmt.Println(pt.NumRowsForTest())
289+
t.Fatalf("The data is not inserted, in buffer now.")
290+
}
291+
pt.Flush()
292+
293+
if len(ins.data) != 1 {
294+
fmt.Println(len(ins.data))
295+
t.Fatalf("Number of rows in inserter is wrong.")
296+
}
297+
if ins.data[0].(*schema.PTTest).Parseinfo.TaskFileName != "gs://fake-bucket/fake-archive.tgz" {
298+
t.Fatalf("Task filename is wrong.")
299+
}
300+
}
301+
274302
func TestPTPollutionCheck(t *testing.T) {
275303
ins := &inMemoryInserter{}
276304
pt := parser.NewPTParser(ins)
@@ -345,7 +373,7 @@ func TestPTPollutionCheck(t *testing.T) {
345373
// Insert the 4th test in the buffer to BigQuery.
346374
pt.ProcessLastTests()
347375
if pt.NumRowsForTest() != 4 {
348-
t.Fatalf("Number of tests in buffer not correct, expect 4, actually %d.", ins.RowsInBuffer())
376+
t.Fatalf("Number of tests in buffer not correct, expect 0, actually %d.", ins.RowsInBuffer())
349377
}
350378
}
351379

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
traceroute [(91.239.96.102:33456) -> (2.80.132.33:33457)], protocol icmp, algo exhaustive, duration 19 s
2+
1 P(6, 6) 91.239.96.65 (91.239.96.65) 0.246/0.284/0.314/0.020 ms
3+
2 P(6, 6) mx-lj1-ge-0-0-3-v110.amis.net (90.157.211.89) 0.984/4.166/19.768/6.978 ms
4+
3 P(6, 6) mx-vi1-te-0-0-0.amis.net (212.18.44.142) 8.602/13.981/40.600/11.904 ms
5+
4 P(6, 6) te0-0-2.frk1-cr1.cprm.net (80.81.192.38) 22.939/25.367/26.480/1.193 ms
6+
5 P(6, 6) ams1-cr1-te0-0-2.cprm.net (195.8.1.33) 29.842/33.365/43.589/4.696 ms
7+
6 P(6, 6) lon1-cr1-te7-0-5.cprm.net (195.8.0.249) 74.040/77.631/81.690/2.422 ms
8+
7 P(6, 6) lis2-cr1-be3.cprm.net (195.8.0.217) 76.171/78.649/81.650/1.768 ms !T2
9+
8 P(6, 6) bt-cr1-hu5-0-0.cprm.net (195.8.1.58) 74.433/88.352/124.008/17.892 ms !T3
10+
9 P(6, 6) dvs-cr1-hu2.cprm.net (195.8.1.13) 74.754/76.854/78.521/1.361 ms
11+
10 P(6, 6) telepac4-huge.cprm.net (195.8.10.206) 76.260/78.578/81.592/1.717 ms
12+
11 P(6, 6) 194.65.12.153 (194.65.12.153) 74.305/83.235/123.161/17.875 ms
13+
12 P(0, 6)
14+
13 P(0, 6)
15+
14 P(0, 6)
16+
17+

0 commit comments

Comments
 (0)