github.com/pingcap/chaos@v0.0.0-20190710112158-c86faf4b3719/pkg/verify/suit.go (about)

     1  package verify
     2  
     3  import (
     4  	"log"
     5  
     6  	"github.com/pingcap/chaos/pkg/core"
     7  	"github.com/pingcap/chaos/pkg/history"
     8  )
     9  
    10  // Suit collects a checker, a model and a parser.
    11  type Suit struct {
    12  	Checker core.Checker
    13  	Model   core.Model
    14  	Parser  history.RecordParser
    15  }
    16  
    17  // Verify creates the verifier from model name and verfies the history file.
    18  func (s Suit) Verify(historyFile string) {
    19  	if s.Model == nil {
    20  		log.Printf("begin to check %s", s.Checker.Name())
    21  	} else {
    22  		log.Printf("begin to check %s with %s", s.Model.Name(), s.Checker.Name())
    23  	}
    24  	ops, state, err := history.ReadHistory(historyFile, s.Parser)
    25  	if err != nil {
    26  		log.Fatalf("verify failed: %v", err)
    27  	}
    28  
    29  	ops, err = history.CompleteOperations(ops, s.Parser)
    30  	if err != nil {
    31  		log.Fatalf("verify failed: %v", err)
    32  	}
    33  
    34  	if s.Model != nil {
    35  		s.Model.Prepare(state)
    36  	}
    37  	ok, err := s.Checker.Check(s.Model, ops)
    38  	if err != nil {
    39  		log.Fatalf("verify history failed %v", err)
    40  	}
    41  
    42  	if !ok {
    43  		log.Fatalf("history %s is not valid", historyFile)
    44  	} else {
    45  		log.Printf("history %s is valid", historyFile)
    46  	}
    47  }