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 {
txGrp []expTxLen
}
var expDefaultRead = []expTxGrp{
{
var expDefaultRead = map[TxType]expTxGrp{
BeReq: {
expTx: 1,
txGrp: []expTxLen{{
expRecs: undefLen,
......@@ -154,7 +154,7 @@ var expDefaultRead = []expTxGrp{
recs: nil,
}}},
},
{
Req: {
expTx: 1,
txGrp: []expTxLen{{
expRecs: undefLen,
......@@ -167,7 +167,7 @@ var expDefaultRead = []expTxGrp{
recs: nil,
}}},
},
{
Sess: {
expTx: 1,
txGrp: []expTxLen{{
expRecs: 5,
......@@ -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) {
if tx.Type != BeReq {
t.Fatalf("checkBereq() tx.Type want=BeReq got=%s", tx.Type)
......@@ -432,26 +421,30 @@ func TestE2EDefaultRead(t *testing.T) {
t.Fatal("Attach(default):", err)
}
statusChan := make(chan Status)
txChan := make(chan []Tx, 100)
var status Status
var txGrps [][]Tx
rdHndlr := func(txGrp []Tx, rdstatus Status) bool {
switch rdstatus {
case More:
txChan <- txGrp
txGrps = append(txGrps, txGrp)
if len(txGrps) == 3 {
return false
}
return true
default:
statusChan <- rdstatus
status = rdstatus
return false
}
}
stopChan := make(chan bool)
readFailed := false
go func() {
err := l.Read(rdHndlr, nil)
if err != nil {
t.Fatal("Read(): " + err.Error())
readFailed = true
return
}
stopChan <- true
}()
client := &http.Client{}
......@@ -465,29 +458,20 @@ func TestE2EDefaultRead(t *testing.T) {
t.Fatal("/uncacheable Response", err)
}
var txGrps [][]Tx
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
}
}
<-stopChan
if readFailed {
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 {
tx := txGrp[0]
checkTxGrp(t, txGrp, expDefaultRead[tx.Type])
if tx.Type == BeReq {
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