Parcourir la source

refactor(test): let the processor test return constant result

describe stream map now prints in order instead of random.
Add logs for window testings to diagnose
ngjaying il y a 5 ans
Parent
commit
d3eda315f8
2 fichiers modifiés avec 22 ajouts et 5 suppressions
  1. 8 3
      common/util.go
  2. 14 2
      xsql/processors/xsql_processor_test.go

+ 8 - 3
common/util.go

@@ -12,6 +12,7 @@ import (
 	"os"
 	"path"
 	"path/filepath"
+	"sort"
 	"strings"
 )
 
@@ -208,9 +209,13 @@ func (m *SimpleKVStore) Keys() (keys []string, err error) {
 }
 
 func PrintMap(m map[string]string, buff *bytes.Buffer) {
-
-	for k, v := range m {
-		buff.WriteString(fmt.Sprintf("%s: %s\n", k, v))
+	si := make([]string, 0, len(m))
+	for s := range m {
+		si = append(si, s)
+	}
+	sort.Strings(si)
+	for _, s := range si {
+		buff.WriteString(fmt.Sprintf("%s: %s\n", s, m[s]))
 	}
 }
 

+ 14 - 2
xsql/processors/xsql_processor_test.go

@@ -1003,12 +1003,18 @@ func TestWindow(t *testing.T) {
 				default:
 				}
 			}
-			for retry := 100; retry > 0; retry-- {
+			retry := 100
+			for ; retry > 0; retry-- {
 				if err := compareMetrics(tp, tt.m, tt.sql); err == nil {
 					break
 				}
+				t.Logf("wait to try another %d times", retry)
 				time.Sleep(time.Duration(retry) * time.Millisecond)
 			}
+			if retry == 0 {
+				err := compareMetrics(tp, tt.m, tt.sql)
+				t.Errorf("could not get correct metrics: %v", err)
+			}
 		}()
 		results := mockSink.GetResults()
 		var maps [][]map[string]interface{}
@@ -1730,12 +1736,18 @@ func TestEventWindow(t *testing.T) {
 			}
 			mockClock := test.GetMockClock()
 			mockClock.Add(1000 * time.Millisecond)
-			for retry := 100; retry > 0; retry-- {
+			retry := 100
+			for ; retry > 0; retry-- {
 				if err := compareMetrics(tp, tt.m, tt.sql); err == nil {
 					break
 				}
+				t.Logf("wait to try another %d times", retry)
 				time.Sleep(time.Duration(retry) * time.Millisecond)
 			}
+			if retry == 0 {
+				err := compareMetrics(tp, tt.m, tt.sql)
+				t.Errorf("could not get correct metrics: %v", err)
+			}
 		}()
 		results := mockSink.GetResults()
 		var maps [][]map[string]interface{}