From fc9f253c89f86d5ddb4ca2788bf0906d67340536 Mon Sep 17 00:00:00 2001 From: RoxyFarhad <40992044+RoxyFarhad@users.noreply.github.com> Date: Fri, 16 Feb 2024 12:12:16 -0500 Subject: [PATCH] App 3820: pass timestamp to onAnswererliveness (#247) --- rpc/dial_test.go | 3 ++- rpc/wrtc_call_queue_mongodb.go | 6 +++--- rpc/wrtc_call_queue_mongodb_test.go | 9 +++++---- rpc/wrtc_client_test.go | 16 +++++++++++----- rpc/wrtc_signaling_test.go | 4 +++- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/rpc/dial_test.go b/rpc/dial_test.go index 54d32afb..3591695d 100644 --- a/rpc/dial_test.go +++ b/rpc/dial_test.go @@ -49,7 +49,8 @@ func TestDialWithMongoDBQueue(t *testing.T) { logger := golog.NewTestLogger(t) client := testutils.BackingMongoDBClient(t) test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) - signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, func(hosts []string) {}) + signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, + func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) defer func() { test.That(t, signalingCallQueue.Close(), test.ShouldBeNil) diff --git a/rpc/wrtc_call_queue_mongodb.go b/rpc/wrtc_call_queue_mongodb.go index d6658ca9..779d6e21 100644 --- a/rpc/wrtc_call_queue_mongodb.go +++ b/rpc/wrtc_call_queue_mongodb.go @@ -92,7 +92,7 @@ type mongoDBWebRTCCallQueue struct { csCtxCancel func() // function to update access times on robot parts based on this call queue - activeAnswerersfunc *func(hostnames []string) + activeAnswerersfunc *func(hostnames []string, atTime time.Time) // 1 caller/answerer -> 1 caller id -> 1 event stream callExchangeSubs map[string]map[*mongodbCallExchange]struct{} @@ -131,7 +131,7 @@ func NewMongoDBWebRTCCallQueue( maxHostCallers uint64, client *mongo.Client, logger golog.Logger, - activeAnswerersfunc func(hostnames []string), + activeAnswerersfunc func(hostnames []string, atTime time.Time), ) (WebRTCCallQueue, error) { if operatorID == "" { return nil, errors.New("expected non-empty operatorID") @@ -407,7 +407,7 @@ func (queue *mongoDBWebRTCCallQueue) operatorLivenessLoop() { } if queue.activeAnswerersfunc != nil { - (*queue.activeAnswerersfunc)(hostsWithAnswerers) + (*queue.activeAnswerersfunc)(hostsWithAnswerers, time.Now()) } } } diff --git a/rpc/wrtc_call_queue_mongodb_test.go b/rpc/wrtc_call_queue_mongodb_test.go index 75997263..174146c5 100644 --- a/rpc/wrtc_call_queue_mongodb_test.go +++ b/rpc/wrtc_call_queue_mongodb_test.go @@ -21,7 +21,8 @@ func TestMongoDBWebRTCCallQueue(t *testing.T) { t.Helper() test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) logger := golog.NewTestLogger(t) - callQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, func(hosts []string) {}) + callQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, + func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) return callQueue, callQueue, func() { test.That(t, callQueue.Close(), test.ShouldBeNil) @@ -39,11 +40,11 @@ func TestMongoDBWebRTCCallQueueMulti(t *testing.T) { test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) logger := golog.NewTestLogger(t) callerQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString()+"-caller", - maxCallerQueueSize, client, logger, func(hosts []string) {}) + maxCallerQueueSize, client, logger, func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) answererQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString()+"-answerer", - maxCallerQueueSize, client, logger, func(hosts []string) {}) + maxCallerQueueSize, client, logger, func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) return callerQueue, answererQueue, func() { test.That(t, callerQueue.Close(), test.ShouldBeNil) @@ -168,7 +169,7 @@ func TestMongoDBWebRTCCallQueueMulti(t *testing.T) { test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) answererQueue, err := NewMongoDBWebRTCCallQueue( context.Background(), uuid.NewString()+"-answerer", - 1, client, logger, func(hostnames []string) { activeAnswererChannelStub <- len(hostnames) }) + 1, client, logger, func(hostnames []string, atTime time.Time) { activeAnswererChannelStub <- len(hostnames) }) test.That(t, err, test.ShouldBeNil) defer answererQueue.Close() diff --git a/rpc/wrtc_client_test.go b/rpc/wrtc_client_test.go index 81a94cd3..86917df1 100644 --- a/rpc/wrtc_client_test.go +++ b/rpc/wrtc_client_test.go @@ -7,6 +7,7 @@ import ( "net" "strings" "testing" + "time" "github.com/edaniels/golog" "github.com/google/uuid" @@ -39,7 +40,8 @@ func TestWebRTCClientServerWithMongoDBQueue(t *testing.T) { logger := golog.NewTestLogger(t) client := testutils.BackingMongoDBClient(t) test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) - signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, func(hosts []string) {}) + signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, + func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) defer func() { test.That(t, signalingCallQueue.Close(), test.ShouldBeNil) @@ -131,7 +133,8 @@ func TestWebRTCClientDialCancelWithMongoDBQueue(t *testing.T) { logger := golog.NewTestLogger(t) client := testutils.BackingMongoDBClient(t) test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) - signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, func(hosts []string) {}) + signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, + func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) defer func() { test.That(t, signalingCallQueue.Close(), test.ShouldBeNil) @@ -217,7 +220,8 @@ func TestWebRTCClientDialReflectAnswererErrorWithMongoDBQueue(t *testing.T) { logger := golog.NewTestLogger(t) client := testutils.BackingMongoDBClient(t) test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) - signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, func(hosts []string) {}) + signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, + func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) defer func() { test.That(t, signalingCallQueue.Close(), test.ShouldBeNil) @@ -308,7 +312,8 @@ func TestWebRTCClientDialConcurrentWithMongoDBQueue(t *testing.T) { logger := golog.NewTestLogger(t) client := testutils.BackingMongoDBClient(t) test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) - signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, func(hosts []string) {}) + signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, + func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) defer func() { test.That(t, signalingCallQueue.Close(), test.ShouldBeNil) @@ -447,7 +452,8 @@ func TestWebRTCClientAnswerConcurrentWithMongoDBQueue(t *testing.T) { logger := golog.NewTestLogger(t) client := testutils.BackingMongoDBClient(t) test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) - signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, func(hosts []string) {}) + signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, + func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) defer func() { test.That(t, signalingCallQueue.Close(), test.ShouldBeNil) diff --git a/rpc/wrtc_signaling_test.go b/rpc/wrtc_signaling_test.go index f01367bd..fa6865f1 100644 --- a/rpc/wrtc_signaling_test.go +++ b/rpc/wrtc_signaling_test.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "testing" + "time" "github.com/edaniels/golog" "github.com/google/uuid" @@ -35,7 +36,8 @@ func TestWebRTCSignalingWithMongoDBQueue(t *testing.T) { logger := golog.NewTestLogger(t) client := testutils.BackingMongoDBClient(t) test.That(t, client.Database(mongodbWebRTCCallQueueDBName).Drop(context.Background()), test.ShouldBeNil) - signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, func(hosts []string) {}) + signalingCallQueue, err := NewMongoDBWebRTCCallQueue(context.Background(), uuid.NewString(), 50, client, logger, + func(hosts []string, atTime time.Time) {}) test.That(t, err, test.ShouldBeNil) defer func() { test.That(t, signalingCallQueue.Close(), test.ShouldBeNil)