Commit b70e72db authored by Geoff Simmons's avatar Geoff Simmons

Make the e2e test for Log.Read() robuster.

parent 7fd59f69
...@@ -140,8 +140,8 @@ type expTxGrp struct { ...@@ -140,8 +140,8 @@ type expTxGrp struct {
txGrp []expTxLen txGrp []expTxLen
} }
var expDefaultRead = []expTxGrp{ var expDefaultRead = map[TxType]expTxGrp{
{ BeReq: {
expTx: 1, expTx: 1,
txGrp: []expTxLen{{ txGrp: []expTxLen{{
expRecs: undefLen, expRecs: undefLen,
...@@ -154,7 +154,7 @@ var expDefaultRead = []expTxGrp{ ...@@ -154,7 +154,7 @@ var expDefaultRead = []expTxGrp{
recs: nil, recs: nil,
}}}, }}},
}, },
{ Req: {
expTx: 1, expTx: 1,
txGrp: []expTxLen{{ txGrp: []expTxLen{{
expRecs: undefLen, expRecs: undefLen,
...@@ -167,7 +167,7 @@ var expDefaultRead = []expTxGrp{ ...@@ -167,7 +167,7 @@ var expDefaultRead = []expTxGrp{
recs: nil, recs: nil,
}}}, }}},
}, },
{ Sess: {
expTx: 1, expTx: 1,
txGrp: []expTxLen{{ txGrp: []expTxLen{{
expRecs: 5, expRecs: 5,
...@@ -299,17 +299,6 @@ func checkTxGrp(t *testing.T, txGrp []Tx, expTxGrp expTxGrp) { ...@@ -299,17 +299,6 @@ func checkTxGrp(t *testing.T, txGrp []Tx, expTxGrp expTxGrp) {
} }
} }
func checkTxGrps(t *testing.T, txGrps [][]Tx, expTxGrps []expTxGrp) {
if len(txGrps) != len(expTxGrps) {
t.Fatalf("number of tx groups got=%v want=%v", len(txGrps),
len(expTxGrps))
return
}
for i, txGrp := range txGrps {
checkTxGrp(t, txGrp, expTxGrps[i])
}
}
func checkBereq(t *testing.T, tx Tx, req http.Request) { func checkBereq(t *testing.T, tx Tx, req http.Request) {
if tx.Type != BeReq { if tx.Type != BeReq {
t.Fatalf("checkBereq() tx.Type want=BeReq got=%s", tx.Type) t.Fatalf("checkBereq() tx.Type want=BeReq got=%s", tx.Type)
...@@ -432,26 +421,30 @@ func TestE2EDefaultRead(t *testing.T) { ...@@ -432,26 +421,30 @@ func TestE2EDefaultRead(t *testing.T) {
t.Fatal("Attach(default):", err) t.Fatal("Attach(default):", err)
} }
statusChan := make(chan Status) var status Status
txChan := make(chan []Tx, 100) var txGrps [][]Tx
rdHndlr := func(txGrp []Tx, rdstatus Status) bool { rdHndlr := func(txGrp []Tx, rdstatus Status) bool {
switch rdstatus { switch rdstatus {
case More: case More:
txChan <- txGrp txGrps = append(txGrps, txGrp)
if len(txGrps) == 3 {
return false
}
return true return true
default: default:
statusChan <- rdstatus status = rdstatus
return false return false
} }
} }
stopChan := make(chan bool)
readFailed := false readFailed := false
go func() { go func() {
err := l.Read(rdHndlr, nil) err := l.Read(rdHndlr, nil)
if err != nil { if err != nil {
t.Fatal("Read(): " + err.Error()) t.Fatal("Read(): " + err.Error())
readFailed = true readFailed = true
return
} }
stopChan <- true
}() }()
client := &http.Client{} client := &http.Client{}
...@@ -465,29 +458,20 @@ func TestE2EDefaultRead(t *testing.T) { ...@@ -465,29 +458,20 @@ func TestE2EDefaultRead(t *testing.T) {
t.Fatal("/uncacheable Response", err) t.Fatal("/uncacheable Response", err)
} }
var txGrps [][]Tx <-stopChan
TX:
for {
select {
case status := <-statusChan:
t.Fatal("status", status)
return
case txGrp := <-txChan:
txGrps = append(txGrps, txGrp)
if len(txGrps) == 3 {
break TX
}
continue
}
}
if readFailed { if readFailed {
return return
} }
if status != Stopped {
t.Errorf("End read status want=%v got=%v", Stopped, status)
}
checkTxGrps(t, txGrps, expDefaultRead) if len(txGrps) != 3 {
t.Errorf("number of tx groups want=3 got=%v", len(txGrps))
}
for _, txGrp := range txGrps { for _, txGrp := range txGrps {
tx := txGrp[0] tx := txGrp[0]
checkTxGrp(t, txGrp, expDefaultRead[tx.Type])
if tx.Type == BeReq { if tx.Type == BeReq {
checkBereq(t, tx, *req) checkBereq(t, tx, *req)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment