@@ -29,10 +29,10 @@ import (
29
29
const bufSize = 1024
30
30
31
31
var (
32
- listener * bufconn.Listener
33
- postClient post.PostServiceClient
34
- calledUpdatePost bool
35
- blockCh = make (chan struct {})
32
+ listener * bufconn.Listener
33
+ postClient post.PostServiceClient
34
+ updateDone = make ( chan struct {})
35
+ blockCh = make (chan struct {})
36
36
)
37
37
38
38
type clientConfig struct {}
@@ -58,10 +58,16 @@ func (s *PostServer) GetPost(ctx context.Context, req *post.GetPostRequest) (*po
58
58
}
59
59
60
60
func (s * PostServer ) UpdatePost (ctx context.Context , req * post.UpdatePostRequest ) (* post.UpdatePostResponse , error ) {
61
- calledUpdatePost = true
61
+ time .Sleep (2 * time .Second )
62
+ updateDone <- struct {}{}
62
63
return nil , nil
63
64
}
64
65
66
+ func (s * PostServer ) DeletePost (ctx context.Context , req * post.DeletePostRequest ) (* post.DeletePostResponse , error ) {
67
+ time .Sleep (1 * time .Second )
68
+ return nil , status .New (codes .Internal , "failed to delete" ).Err ()
69
+ }
70
+
65
71
func dialer (ctx context.Context , address string ) (net.Conn , error ) {
66
72
return listener .Dial ()
67
73
}
@@ -140,15 +146,21 @@ func TestFederation(t *testing.T) {
140
146
}
141
147
})
142
148
t .Run ("UpdatePost" , func (t * testing.T ) {
143
- if _ , err := client .UpdatePost (ctx , & federation.UpdatePostRequest {
149
+ _ , err := client .UpdatePost (ctx , & federation.UpdatePostRequest {
144
150
Id : "foo" ,
145
- }); err != nil {
146
- t .Fatal (err )
151
+ })
152
+ if err == nil {
153
+ t .Fatal ("expected error" )
154
+ }
155
+ st , ok := status .FromError (err )
156
+ if ! ok {
157
+ t .Fatal ("failed to get gRPC status error" )
147
158
}
148
- if ! calledUpdatePost {
149
- t .Fatal ("failed to call UpdatePost method" )
159
+ if st . Code () != codes . Internal {
160
+ t .Fatalf ("failed to get status code: %s" , st . Code () )
150
161
}
151
162
})
152
163
blockCh <- struct {}{}
164
+ <- updateDone
153
165
time .Sleep (100 * time .Millisecond )
154
166
}
0 commit comments