add Flush
This commit is contained in:
		| @@ -92,6 +92,7 @@ func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb. | ||||
|  | ||||
| 	if md, ok := metadata.FromContext(ctx); gzipAccepted(md) && ok { | ||||
| 		md.Set(contentEncodingHeader, "gzip") | ||||
| 		ctx = metadata.NewIncomingContext(ctx, md) | ||||
| 		gz := gzipPool.Get().(*gzip.Writer) | ||||
| 		defer gzipPool.Put(gz) | ||||
|  | ||||
| @@ -99,6 +100,7 @@ func (h *Handler) Metrics(ctx context.Context, req *codecpb.Frame, rsp *codecpb. | ||||
| 		defer gz.Close() | ||||
|  | ||||
| 		w = gz | ||||
| 		gz.Flush() | ||||
| 	} | ||||
|  | ||||
| 	if err := h.opts.Meter.Write(w, h.opts.MeterOptions...); err != nil { | ||||
|   | ||||
							
								
								
									
										49
									
								
								handler/meter/meter_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								handler/meter/meter_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| package meter | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"testing" | ||||
|  | ||||
| 	codecpb "go.unistack.org/micro-proto/v4/codec" | ||||
| ) | ||||
|  | ||||
| func TestHandler_Metrics(t *testing.T) { | ||||
| 	type fields struct { | ||||
| 		opts Options | ||||
| 	} | ||||
| 	type args struct { | ||||
| 		ctx context.Context | ||||
| 		req *codecpb.Frame | ||||
| 		rsp *codecpb.Frame | ||||
| 	} | ||||
| 	tests := []struct { | ||||
| 		name    string | ||||
| 		fields  fields | ||||
| 		args    args | ||||
| 		wantErr bool | ||||
| 	}{ | ||||
| 		{ | ||||
| 			"Test #1", | ||||
| 			fields{ | ||||
| 				opts: NewOptions(), | ||||
| 			}, | ||||
| 			args{ | ||||
| 				context.Background(), | ||||
| 				&codecpb.Frame{Data: []byte("gzip")}, | ||||
| 				&codecpb.Frame{}, | ||||
| 			}, | ||||
| 			true, | ||||
| 		}, | ||||
| 	} | ||||
| 	for _, tt := range tests { | ||||
| 		t.Run(tt.name, func(t *testing.T) { | ||||
| 			h := &Handler{ | ||||
| 				opts: tt.fields.opts, | ||||
| 			} | ||||
| 			if err := h.Metrics(tt.args.ctx, tt.args.req, tt.args.rsp); (err != nil) != tt.wantErr { | ||||
| 				t.Errorf("Metrics() error = %v, wantErr %v", err, tt.wantErr) | ||||
| 			} | ||||
| 			t.Logf("RSP: %v", tt.args.rsp.Data) | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user