mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 18:17:55 +00:00 
			
		
		
		
	Allow more time for CI events test (#22589)
CI is sometimes slow, so 100ms was not enough time for all events to be sent and processed in `http/events_test.go`. We bumped that timeout to a full 1 second, but also added a trick at the end to shorten the timeout once the expected number of events have been receieved. This way, once the test has passed, we only wait 100ms for any "extra" events to make the test fail, instead of waiting for the full 1 second before we let the test pass. This should keep the test relatively fast, while still allowing for it to be slow sometimes.
This commit is contained in:
		 Christopher Swenson
					Christopher Swenson
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							64dd7a939f
						
					
				
				
					commit
					917a5863fe
				
			| @@ -235,7 +235,8 @@ func TestEventsSubscribeNamespaces(t *testing.T) { | ||||
| 				conn.Close(websocket.StatusNormalClosure, "") | ||||
| 			}) | ||||
| 			sendEvents() | ||||
| 			ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond) | ||||
| 			// CI is sometimes slow, so this timeout is high initially | ||||
| 			ctx, cancel := context.WithTimeout(ctx, 1*time.Second) | ||||
| 			defer cancel() | ||||
| 			gotEvents := 0 | ||||
| 			for { | ||||
| @@ -250,6 +251,14 @@ func TestEventsSubscribeNamespaces(t *testing.T) { | ||||
| 				} | ||||
| 				t.Log(string(msg)) | ||||
| 				gotEvents += 1 | ||||
|  | ||||
| 				// if we got as many as we expect, shorten the test so we don't waste time, | ||||
| 				// but still allow time for "extra" events to come in and make us fail | ||||
| 				if gotEvents == testCase.expectedEvents { | ||||
| 					ctx2, cancel2 := context.WithTimeout(ctx, 100*time.Millisecond) | ||||
| 					t.Cleanup(cancel2) | ||||
| 					ctx = ctx2 | ||||
| 				} | ||||
| 			} | ||||
| 			assert.Equal(t, testCase.expectedEvents, gotEvents) | ||||
| 		}) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user