@@ -2,6 +2,7 @@ package internal_integration_test |
2 | 2 |
|
3 | 3 | import ( |
4 | 4 | "context" |
| 5 | + "strconv" |
5 | 6 | "sync" |
6 | 7 | "time" |
7 | 8 |
|
@@ -1013,71 +1014,95 @@ var _ = Describe("Interrupts and Timeouts", func() { |
1013 | 1014 | }) |
1014 | 1015 |
|
1015 | 1016 | Describe("passing contexts to TableEntries", func() { |
1016 | | - var times *TimeMap |
1017 | | - BeforeEach(func() { |
1018 | | - times = NewTimeMap() |
| 1017 | + Describe("the happy path", func() { |
| 1018 | + var times *TimeMap |
| 1019 | + BeforeEach(func() { |
| 1020 | + times = NewTimeMap() |
1019 | 1021 |
|
1020 | | - success, _ := RunFixture(CurrentSpecReport().LeafNodeText, func() { |
1021 | | - Context("container", func() { |
1022 | | - DescribeTable("timeout table", |
1023 | | - func(c SpecContext, d context.Context, key string) { |
1024 | | - key = d.Value("key").(string) + key |
1025 | | - rt.Run(CurrentSpecReport().LeafNodeText) |
1026 | | - t := time.Now() |
1027 | | - <-c.Done() |
1028 | | - times.Set(key, time.Since(t)) |
1029 | | - }, |
1030 | | - func(d context.Context, key string) string { |
1031 | | - key = d.Value("key").(string) + key |
1032 | | - return key |
1033 | | - }, |
1034 | | - Entry(nil, context.WithValue(context.Background(), "key", "entry-"), "1", NodeTimeout(time.Millisecond)*100), |
1035 | | - Entry(nil, context.WithValue(context.Background(), "key", "entry-"), "2", SpecTimeout(time.Millisecond)*150), |
1036 | | - ) |
1037 | | - |
1038 | | - DescribeTable("timeout table", |
1039 | | - func(c context.Context, key string) { |
1040 | | - rt.Run(CurrentSpecReport().LeafNodeText) |
1041 | | - t := time.Now() |
1042 | | - <-c.Done() |
1043 | | - times.Set(key, time.Since(t)) |
1044 | | - }, |
1045 | | - func(key string) string { |
1046 | | - return key |
1047 | | - }, |
1048 | | - Entry(nil, "entry-3", NodeTimeout(time.Millisecond)*100), |
1049 | | - Entry(nil, "entry-4", SpecTimeout(time.Millisecond)*150), |
1050 | | - ) |
1051 | | - |
1052 | | - DescribeTable("timeout table", |
1053 | | - func(c context.Context, key string) { |
1054 | | - key = c.Value("key").(string) + key |
1055 | | - rt.Run(CurrentSpecReport().LeafNodeText + "-" + key) |
1056 | | - }, |
1057 | | - func(d context.Context, key string) string { |
1058 | | - key = d.Value("key").(string) + key |
1059 | | - return key |
1060 | | - }, |
1061 | | - Entry(nil, context.WithValue(context.Background(), "key", "entry-"), "5"), |
1062 | | - Entry(nil, context.WithValue(context.Background(), "key", "entry-"), "6"), |
1063 | | - ) |
| 1022 | + success, _ := RunFixture(CurrentSpecReport().LeafNodeText, func() { |
| 1023 | + Context("container", func() { |
| 1024 | + DescribeTable("timeout table", |
| 1025 | + func(c SpecContext, d context.Context, key string) { |
| 1026 | + key = d.Value("key").(string) + key |
| 1027 | + rt.Run(CurrentSpecReport().LeafNodeText) |
| 1028 | + t := time.Now() |
| 1029 | + <-c.Done() |
| 1030 | + times.Set(key, time.Since(t)) |
| 1031 | + }, |
| 1032 | + func(d context.Context, key string) string { |
| 1033 | + key = d.Value("key").(string) + key |
| 1034 | + return key |
| 1035 | + }, |
| 1036 | + Entry(nil, context.WithValue(context.Background(), "key", "entry-"), "1", NodeTimeout(time.Millisecond)*100), |
| 1037 | + Entry(nil, context.WithValue(context.Background(), "key", "entry-"), "2", SpecTimeout(time.Millisecond)*150), |
| 1038 | + ) |
| 1039 | + |
| 1040 | + DescribeTable("timeout table", |
| 1041 | + func(c context.Context, key string) { |
| 1042 | + rt.Run(CurrentSpecReport().LeafNodeText) |
| 1043 | + t := time.Now() |
| 1044 | + <-c.Done() |
| 1045 | + times.Set(key, time.Since(t)) |
| 1046 | + }, |
| 1047 | + func(key string) string { |
| 1048 | + return key |
| 1049 | + }, |
| 1050 | + Entry(nil, "entry-3", NodeTimeout(time.Millisecond)*100), |
| 1051 | + Entry(nil, "entry-4", SpecTimeout(time.Millisecond)*150), |
| 1052 | + ) |
| 1053 | + |
| 1054 | + DescribeTable("timeout table", |
| 1055 | + func(c context.Context, key string) { |
| 1056 | + key = c.Value("key").(string) + key |
| 1057 | + rt.Run(CurrentSpecReport().LeafNodeText + "-" + key) |
| 1058 | + }, |
| 1059 | + func(d context.Context, key string) string { |
| 1060 | + key = d.Value("key").(string) + key |
| 1061 | + return key |
| 1062 | + }, |
| 1063 | + Entry(nil, context.WithValue(context.Background(), "key", "entry-"), "5"), |
| 1064 | + Entry(nil, context.WithValue(context.Background(), "key", "entry-"), "6"), |
| 1065 | + ) |
| 1066 | + }) |
1064 | 1067 | }) |
| 1068 | + Ω(success).Should(Equal(false)) |
| 1069 | + }) |
| 1070 | + |
| 1071 | + It("should work", func() { |
| 1072 | + Ω(rt).Should(HaveTracked("entry-1", "entry-2", "entry-3", "entry-4", "entry-5-entry-5", "entry-6-entry-6")) |
| 1073 | + Ω(reporter.Did.Find("entry-1")).Should(HaveTimedOut()) |
| 1074 | + Ω(reporter.Did.Find("entry-2")).Should(HaveTimedOut()) |
| 1075 | + Ω(reporter.Did.Find("entry-3")).Should(HaveTimedOut()) |
| 1076 | + Ω(reporter.Did.Find("entry-4")).Should(HaveTimedOut()) |
| 1077 | + Ω(reporter.Did.Find("entry-1").Failure.ProgressReport.CurrentNodeType).Should(Equal(types.NodeTypeIt)) |
| 1078 | + |
| 1079 | + Ω(times.Get("entry-1")).Should(BeNumerically("~", 100*time.Millisecond, 50*time.Millisecond)) |
| 1080 | + Ω(times.Get("entry-2")).Should(BeNumerically("~", 150*time.Millisecond, 50*time.Millisecond)) |
| 1081 | + Ω(times.Get("entry-3")).Should(BeNumerically("~", 100*time.Millisecond, 50*time.Millisecond)) |
| 1082 | + Ω(times.Get("entry-4")).Should(BeNumerically("~", 150*time.Millisecond, 50*time.Millisecond)) |
1065 | 1083 | }) |
1066 | | - Ω(success).Should(Equal(false)) |
1067 | 1084 | }) |
1068 | 1085 |
|
1069 | | - It("should work", func() { |
1070 | | - Ω(rt).Should(HaveTracked("entry-1", "entry-2", "entry-3", "entry-4", "entry-5-entry-5", "entry-6-entry-6")) |
1071 | | - Ω(reporter.Did.Find("entry-1")).Should(HaveTimedOut()) |
1072 | | - Ω(reporter.Did.Find("entry-2")).Should(HaveTimedOut()) |
1073 | | - Ω(reporter.Did.Find("entry-3")).Should(HaveTimedOut()) |
1074 | | - Ω(reporter.Did.Find("entry-4")).Should(HaveTimedOut()) |
1075 | | - Ω(reporter.Did.Find("entry-1").Failure.ProgressReport.CurrentNodeType).Should(Equal(types.NodeTypeIt)) |
1076 | | - |
1077 | | - Ω(times.Get("entry-1")).Should(BeNumerically("~", 100*time.Millisecond, 50*time.Millisecond)) |
1078 | | - Ω(times.Get("entry-2")).Should(BeNumerically("~", 150*time.Millisecond, 50*time.Millisecond)) |
1079 | | - Ω(times.Get("entry-3")).Should(BeNumerically("~", 100*time.Millisecond, 50*time.Millisecond)) |
1080 | | - Ω(times.Get("entry-4")).Should(BeNumerically("~", 150*time.Millisecond, 50*time.Millisecond)) |
| 1086 | + Describe("the edge case in #1415", func() { |
| 1087 | + var four = 4 |
| 1088 | + var nSix = -6 |
| 1089 | + DescribeTable("it supports receiving a SpecContext and works with nil parameters", func(ctx context.Context, num *int, s string, cVal string) { |
| 1090 | + Ω(ctx).ShouldNot(BeNil()) |
| 1091 | + if num == nil { |
| 1092 | + Ω(s).Should(Equal("nil")) |
| 1093 | + } else { |
| 1094 | + Ω(s).Should(Equal(strconv.Itoa(*num))) |
| 1095 | + } |
| 1096 | + if cVal != "" { |
| 1097 | + Ω(ctx.Value("key")).Should(Equal(cVal)) |
| 1098 | + } |
| 1099 | + }, |
| 1100 | + Entry("4", &four, "4", ""), |
| 1101 | + Entry("-6", &nSix, "-6", ""), |
| 1102 | + Entry("nil", nil, "nil", ""), |
| 1103 | + Entry("4 with context value", context.WithValue(context.Background(), "key", "val"), &four, "4", "val"), |
| 1104 | + Entry("nil with context value", context.WithValue(context.Background(), "key", "val"), nil, "nil", "val"), |
| 1105 | + ) |
1081 | 1106 | }) |
1082 | 1107 | }) |
1083 | 1108 | }) |