@@ -57,6 +57,16 @@ func (v *ExpensiveView) Renderable(ctx context.Context) (Renderable, error) {
57
57
}
58
58
}
59
59
60
+ type ViewWithTimeout struct {
61
+ Delegate AsRenderable
62
+ Timeout time.Duration
63
+ }
64
+
65
+ func (v ViewWithTimeout ) Renderable (ctx context.Context ) (Renderable , error ) {
66
+ ctx , _ = context .WithTimeout (ctx , v .Timeout )
67
+ return v .Delegate .Renderable (ctx )
68
+ }
69
+
60
70
func TestViewWithChannels (t * testing.T ) {
61
71
t .Run ("successful" , func (t * testing.T ) {
62
72
html , err := Render (context .Background (), NewExpensiveView (false , 1 * time .Millisecond ))
@@ -80,4 +90,16 @@ func TestViewWithChannels(t *testing.T) {
80
90
_ , err := Render (ctx , NewExpensiveView (false , 2 * time .Millisecond ))
81
91
assert .NoError (t , err )
82
92
})
93
+
94
+ t .Run ("with timeout and fallible" , func (t * testing.T ) {
95
+ html , err := Render (context .Background (), FallibleView {
96
+ Child : ViewWithTimeout {
97
+ Delegate : NewExpensiveView (false , 10 * time .Millisecond ),
98
+ Timeout : 2 * time .Millisecond ,
99
+ },
100
+ CapturesErr : context .DeadlineExceeded ,
101
+ })
102
+ assert .NoError (t , err )
103
+ assert .Equal (t , template .HTML (`HEADING` ), html )
104
+ })
83
105
}
0 commit comments