mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Remove metrics race condition in sqs test
To test that the broker responds with a proxy answer if available, have only one valid client offer to ensure metrics will always be in the first multiple of 8.
This commit is contained in:
parent
80374c6d93
commit
9e619a3654
1 changed files with 18 additions and 16 deletions
|
@ -136,26 +136,29 @@ func TestSQS(t *testing.T) {
|
||||||
|
|
||||||
Convey("and responds with a proxy answer if available.", func(c C) {
|
Convey("and responds with a proxy answer if available.", func(c C) {
|
||||||
sqsHandlerContext, sqsCancelFunc := context.WithCancel(context.Background())
|
sqsHandlerContext, sqsCancelFunc := context.WithCancel(context.Background())
|
||||||
|
var numTimes atomic.Uint32
|
||||||
|
|
||||||
mockSQSClient.EXPECT().ReceiveMessage(sqsHandlerContext, &sqsReceiveMessageInput).AnyTimes().DoAndReturn(
|
mockSQSClient.EXPECT().ReceiveMessage(sqsHandlerContext, &sqsReceiveMessageInput).AnyTimes().DoAndReturn(
|
||||||
func(ctx context.Context, input *sqs.ReceiveMessageInput, optFns ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error) {
|
func(ctx context.Context, input *sqs.ReceiveMessageInput, optFns ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error) {
|
||||||
|
|
||||||
|
n := numTimes.Add(1)
|
||||||
|
if n == 1 {
|
||||||
snowflake := ipcCtx.AddSnowflake("fake", "", NATUnrestricted, 0)
|
snowflake := ipcCtx.AddSnowflake("fake", "", NATUnrestricted, 0)
|
||||||
go func(c C) {
|
go func(c C) {
|
||||||
<-snowflake.offerChannel
|
<-snowflake.offerChannel
|
||||||
snowflake.answerChannel <- "fake answer"
|
snowflake.answerChannel <- "fake answer"
|
||||||
}(c)
|
}(c)
|
||||||
return validMessage, nil
|
return validMessage, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("error")
|
||||||
|
|
||||||
})
|
})
|
||||||
mockSQSClient.EXPECT().CreateQueue(sqsHandlerContext, &sqsCreateQueueInput).Return(&sqs.CreateQueueOutput{
|
mockSQSClient.EXPECT().CreateQueue(sqsHandlerContext, &sqsCreateQueueInput).Return(&sqs.CreateQueueOutput{
|
||||||
QueueUrl: responseQueueURL,
|
QueueUrl: responseQueueURL,
|
||||||
}, nil).AnyTimes()
|
}, nil).AnyTimes()
|
||||||
mockSQSClient.EXPECT().DeleteMessage(gomock.Any(), gomock.Any()).AnyTimes()
|
mockSQSClient.EXPECT().DeleteMessage(gomock.Any(), gomock.Any()).AnyTimes()
|
||||||
var numTimes atomic.Uint32
|
mockSQSClient.EXPECT().SendMessage(sqsHandlerContext, gomock.Any()).Times(1).DoAndReturn(
|
||||||
mockSQSClient.EXPECT().SendMessage(sqsHandlerContext, gomock.Any()).MinTimes(1).DoAndReturn(
|
|
||||||
func(ctx context.Context, input *sqs.SendMessageInput, optFns ...func(*sqs.Options)) (*sqs.SendMessageOutput, error) {
|
func(ctx context.Context, input *sqs.SendMessageInput, optFns ...func(*sqs.Options)) (*sqs.SendMessageOutput, error) {
|
||||||
n := numTimes.Add(1)
|
|
||||||
if n == 1 {
|
|
||||||
c.So(input.MessageBody, ShouldEqual, aws.String("{\"answer\":\"fake answer\"}"))
|
c.So(input.MessageBody, ShouldEqual, aws.String("{\"answer\":\"fake answer\"}"))
|
||||||
// Ensure that match is correctly recorded in metrics
|
// Ensure that match is correctly recorded in metrics
|
||||||
ipcCtx.metrics.printMetrics()
|
ipcCtx.metrics.printMetrics()
|
||||||
|
@ -171,7 +174,6 @@ client-sqs-count 8
|
||||||
client-sqs-ips ??=8
|
client-sqs-ips ??=8
|
||||||
`)
|
`)
|
||||||
sqsCancelFunc()
|
sqsCancelFunc()
|
||||||
}
|
|
||||||
return &sqs.SendMessageOutput{}, nil
|
return &sqs.SendMessageOutput{}, nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue