@@ -20,6 +20,7 @@ package verify
2020import (
2121 "context"
2222 "fmt"
23+ "github.com/apache/skywalking-infra-e2e/internal/constant"
2324 "sync"
2425 "time"
2526
@@ -53,7 +54,8 @@ var Verify = &cobra.Command{
5354 Short : "verify if the actual data match the expected data" ,
5455 RunE : func (cmd * cobra.Command , args []string ) error {
5556 if expected != "" {
56- return verifySingleCase (expected , actual , query )
57+ _ , err := verifySingleCase (expected , actual , query )
58+ return err
5759 }
5860
5961 // If there is no given flags.
@@ -69,34 +71,34 @@ type verifyInfo struct {
6971 failFast bool
7072}
7173
72- func verifySingleCase (expectedFile , actualFile , query string ) error {
74+ func verifySingleCase (expectedFile , actualFile , query string ) ( string , error ) {
7375 expectedData , err := util .ReadFileContent (expectedFile )
7476 if err != nil {
75- return fmt .Errorf ("failed to read the expected data file: %v" , err )
77+ return "" , fmt .Errorf ("failed to read the expected data file: %v" , err )
7678 }
7779
7880 var actualData , sourceName , stderr string
7981 if actualFile != "" {
8082 sourceName = actualFile
8183 actualData , err = util .ReadFileContent (actualFile )
8284 if err != nil {
83- return fmt .Errorf ("failed to read the actual data file: %v" , err )
85+ return "" , fmt .Errorf ("failed to read the actual data file: %v" , err )
8486 }
8587 } else if query != "" {
8688 sourceName = query
8789 actualData , stderr , err = util .ExecuteCommand (query )
8890 if err != nil {
89- return fmt .Errorf ("failed to execute the query: %s, output: %s, error: %v" , query , actualData , stderr )
91+ return "" , fmt .Errorf ("failed to execute the query: %s, output: %s, error: %v" , query , actualData , stderr )
9092 }
9193 }
9294
9395 if err = verifier .Verify (actualData , expectedData ); err != nil {
9496 if me , ok := err .(* verifier.MismatchError ); ok {
95- return fmt .Errorf ("failed to verify the output: %s, error:\n %v" , sourceName , me .Error ())
97+ return actualData , fmt .Errorf ("failed to verify the output: %s, error:\n %v" , sourceName , me .Error ())
9698 }
97- return fmt .Errorf ("failed to verify the output: %s, error:\n %v" , sourceName , err )
99+ return actualData , fmt .Errorf ("failed to verify the output: %s, error:\n %v" , sourceName , err )
98100 }
99- return nil
101+ return actualData , nil
100102}
101103
102104// concurrentlyVerifySingleCase verifies a single case in concurrency mode,
@@ -127,7 +129,7 @@ func concurrentlyVerifySingleCase(
127129 res .Skip = true
128130 return res
129131 default :
130- if err := verifySingleCase (v .GetExpected (), v .GetActual (), v .Query ); err == nil {
132+ if d , err := verifySingleCase (v .GetExpected (), v .GetActual (), v .Query ); err == nil {
131133 if current == 0 {
132134 res .Msg = fmt .Sprintf ("verified %v\n " , caseName (v ))
133135 } else {
@@ -138,6 +140,9 @@ func concurrentlyVerifySingleCase(
138140 time .Sleep (verifyInfo .interval )
139141 } else {
140142 res .Msg = fmt .Sprintf ("failed to verify %v, retried %d time(s):" , caseName (v ), current )
143+ if d != "" {
144+ res .Msg += fmt .Sprintf (" the actual data is:\n %s\n " , d )
145+ }
141146 res .Err = err
142147 }
143148 }
@@ -215,7 +220,7 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
215220
216221 if v .GetExpected () == "" {
217222 res [idx ].Skip = false
218- res [idx ].Msg = fmt .Sprintf ("failed to verify %v" , caseName (v ))
223+ res [idx ].Msg = fmt .Sprintf ("%s failed to verify %v" , formatVerificationTime () , caseName (v ))
219224 res [idx ].Err = fmt .Errorf ("the expected data file for %v is not specified" , caseName (v ))
220225
221226 printer .Warning (res [idx ].Msg )
@@ -227,11 +232,11 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
227232 }
228233
229234 for current := 0 ; current <= verifyInfo .retryCount ; current ++ {
230- if e := verifySingleCase (v .GetExpected (), v .GetActual (), v .Query ); e == nil {
235+ if d , e := verifySingleCase (v .GetExpected (), v .GetActual (), v .Query ); e == nil {
231236 if current == 0 {
232- res [idx ].Msg = fmt .Sprintf ("verified %v \n " , caseName (v ))
237+ res [idx ].Msg = fmt .Sprintf ("%s verified %v \n " , formatVerificationTime () , caseName (v ))
233238 } else {
234- res [idx ].Msg = fmt .Sprintf ("verified %v, retried %d time(s)\n " , caseName (v ), current )
239+ res [idx ].Msg = fmt .Sprintf ("%s verified %v, retried %d time(s)\n " , formatVerificationTime () , caseName (v ), current )
235240 }
236241 res [idx ].Skip = false
237242 printer .Success (res [idx ].Msg )
@@ -240,11 +245,15 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
240245 if current == 0 {
241246 printer .UpdateText (fmt .Sprintf ("failed to verify %v, will continue retry:" , caseName (v )))
242247 } else {
243- printer .UpdateText (fmt .Sprintf ("failed to verify %v, retry [%d/%d]" , caseName (v ), current , verifyInfo .retryCount ))
248+ printer .UpdateText (fmt .Sprintf ("failed to verify %v, retry [%d/%d]" , caseName (v ), current ,
249+ verifyInfo .retryCount ))
244250 }
245251 time .Sleep (verifyInfo .interval )
246252 } else {
247- res [idx ].Msg = fmt .Sprintf ("failed to verify %v, retried %d time(s)" , caseName (v ), current )
253+ res [idx ].Msg = fmt .Sprintf ("%s failed to verify %v, retried %d time(s)" , formatVerificationTime (), caseName (v ), current )
254+ if d != "" {
255+ res [idx ].Msg += fmt .Sprintf (", the actual data is:\n %s\n " , d )
256+ }
248257 res [idx ].Err = e
249258 res [idx ].Skip = false
250259 printer .UpdateText (fmt .Sprintf ("failed to verify %v, retry [%d/%d]" , caseName (v ), current , verifyInfo .retryCount ))
@@ -260,6 +269,10 @@ func verifyCasesSerially(verify *config.Verify, verifyInfo *verifyInfo) (err err
260269 return nil
261270}
262271
272+ func formatVerificationTime () string {
273+ return time .Now ().Format (constant .LogTimestampFormat )
274+ }
275+
263276func caseName (v * config.VerifyCase ) string {
264277 if v .Name == "" {
265278 if v .Actual != "" {
0 commit comments