mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-29 16:30:44 +01:00
s3_lifecycle: bound shared metadata subscriptions
This commit is contained in:
1 parent
3c549b33ab
commit
55aa4174ff
4 files changed
+268
-6
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package reader
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type blockingSubscribeClient struct {
|
||||
filer_pb.SeaweedFilerClient
|
||||
request *filer_pb.SubscribeMetadataRequest
|
||||
}
|
||||
|
||||
func (c *blockingSubscribeClient) SubscribeMetadata(ctx context.Context, req *filer_pb.SubscribeMetadataRequest, _ ...grpc.CallOption) (grpc.ServerStreamingClient[filer_pb.SubscribeMetadataResponse], error) {
|
||||
c.request = req
|
||||
return &blockingSubscribeStream{ctx: ctx}, nil
|
||||
}
|
||||
|
||||
type blockingSubscribeStream struct {
|
||||
grpc.ServerStreamingClient[filer_pb.SubscribeMetadataResponse]
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (s *blockingSubscribeStream) Recv() (*filer_pb.SubscribeMetadataResponse, error) {
|
||||
<-s.ctx.Done()
|
||||
return nil, s.ctx.Err()
|
||||
}
|
||||
|
||||
func TestRunTimesOutHalfOpenSubscription(t *testing.T) {
|
||||
client := &blockingSubscribeClient{}
|
||||
r := &Reader{
|
||||
ShardID: 0,
|
||||
BucketsPath: "/buckets",
|
||||
UntilTsNs: 12345,
|
||||
Events: make(chan *Event),
|
||||
ReceiveTimeout: 50 * time.Millisecond,
|
||||
}
|
||||
|
||||
started := time.Now()
|
||||
err := r.Run(context.Background(), client, "test-lifecycle", 7)
|
||||
require.ErrorIs(t, err, ErrReceiveTimeout)
|
||||
assert.Less(t, time.Since(started), time.Second)
|
||||
require.NotNil(t, client.request)
|
||||
assert.Equal(t, int64(12345), client.request.UntilNs)
|
||||
assert.True(t, client.request.ClientSupportsIdleHeartbeat)
|
||||
}
|
||||
Reference in new issue
Block a user