|
@@ -200,6 +200,93 @@ func TestCreateAlreadyExists(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestLogClosed(t *testing.T) {
|
|
|
+ mockClient := newMockClient()
|
|
|
+ stream := &logStream{
|
|
|
+ client: mockClient,
|
|
|
+ closed: true,
|
|
|
+ }
|
|
|
+ err := stream.Log(&logger.Message{})
|
|
|
+ if err == nil {
|
|
|
+ t.Fatal("Expected non-nil error")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestLogBlocking(t *testing.T) {
|
|
|
+ mockClient := newMockClient()
|
|
|
+ stream := &logStream{
|
|
|
+ client: mockClient,
|
|
|
+ messages: make(chan *logger.Message),
|
|
|
+ }
|
|
|
+
|
|
|
+ errorCh := make(chan error, 1)
|
|
|
+ started := make(chan bool)
|
|
|
+ go func() {
|
|
|
+ started <- true
|
|
|
+ err := stream.Log(&logger.Message{})
|
|
|
+ errorCh <- err
|
|
|
+ }()
|
|
|
+ <-started
|
|
|
+ select {
|
|
|
+ case err := <-errorCh:
|
|
|
+ t.Fatal("Expected stream.Log to block: ", err)
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ select {
|
|
|
+ case <-stream.messages:
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ t.Fatal("Expected to be able to read from stream.messages but was unable to")
|
|
|
+ }
|
|
|
+ select {
|
|
|
+ case err := <-errorCh:
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ case <-time.After(30 * time.Second):
|
|
|
+ t.Fatal("timed out waiting for read")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestLogNonBlockingBufferEmpty(t *testing.T) {
|
|
|
+ mockClient := newMockClient()
|
|
|
+ stream := &logStream{
|
|
|
+ client: mockClient,
|
|
|
+ messages: make(chan *logger.Message, 1),
|
|
|
+ logNonBlocking: true,
|
|
|
+ }
|
|
|
+ err := stream.Log(&logger.Message{})
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestLogNonBlockingBufferFull(t *testing.T) {
|
|
|
+ mockClient := newMockClient()
|
|
|
+ stream := &logStream{
|
|
|
+ client: mockClient,
|
|
|
+ messages: make(chan *logger.Message, 1),
|
|
|
+ logNonBlocking: true,
|
|
|
+ }
|
|
|
+ stream.messages <- &logger.Message{}
|
|
|
+ errorCh := make(chan error)
|
|
|
+ started := make(chan bool)
|
|
|
+ go func() {
|
|
|
+ started <- true
|
|
|
+ err := stream.Log(&logger.Message{})
|
|
|
+ errorCh <- err
|
|
|
+ }()
|
|
|
+ <-started
|
|
|
+ select {
|
|
|
+ case err := <-errorCh:
|
|
|
+ if err == nil {
|
|
|
+ t.Fatal("Expected non-nil error")
|
|
|
+ }
|
|
|
+ case <-time.After(30 * time.Second):
|
|
|
+ t.Fatal("Expected Log call to not block")
|
|
|
+ }
|
|
|
+}
|
|
|
func TestPublishBatchSuccess(t *testing.T) {
|
|
|
mockClient := newMockClient()
|
|
|
stream := &logStream{
|
|
@@ -409,8 +496,9 @@ func TestCollectBatchSimple(t *testing.T) {
|
|
|
C: ticks,
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
stream.Log(&logger.Message{
|
|
|
Line: []byte(logline),
|
|
@@ -453,7 +541,9 @@ func TestCollectBatchTicker(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
stream.Log(&logger.Message{
|
|
|
Line: []byte(logline + " 1"),
|
|
@@ -525,7 +615,9 @@ func TestCollectBatchMultilinePattern(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
stream.Log(&logger.Message{
|
|
|
Line: []byte(logline),
|
|
@@ -579,7 +671,9 @@ func BenchmarkCollectBatch(b *testing.B) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
stream.logGenerator(10, 100)
|
|
|
ticks <- time.Time{}
|
|
|
stream.Close()
|
|
@@ -609,7 +703,9 @@ func BenchmarkCollectBatchMultilinePattern(b *testing.B) {
|
|
|
C: ticks,
|
|
|
}
|
|
|
}
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
stream.logGenerator(10, 100)
|
|
|
ticks <- time.Time{}
|
|
|
stream.Close()
|
|
@@ -639,7 +735,9 @@ func TestCollectBatchMultilinePatternMaxEventAge(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
stream.Log(&logger.Message{
|
|
|
Line: []byte(logline),
|
|
@@ -701,7 +799,9 @@ func TestCollectBatchMultilinePatternNegativeEventAge(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
stream.Log(&logger.Message{
|
|
|
Line: []byte(logline),
|
|
@@ -749,7 +849,9 @@ func TestCollectBatchMultilinePatternMaxEventSize(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
// Log max event size
|
|
|
longline := strings.Repeat("A", maximumBytesPerEvent)
|
|
@@ -800,7 +902,9 @@ func TestCollectBatchClose(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
stream.Log(&logger.Message{
|
|
|
Line: []byte(logline),
|
|
@@ -843,7 +947,9 @@ func TestCollectBatchLineSplit(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
longline := strings.Repeat("A", maximumBytesPerEvent)
|
|
|
stream.Log(&logger.Message{
|
|
@@ -890,7 +996,9 @@ func TestCollectBatchMaxEvents(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
line := "A"
|
|
|
for i := 0; i <= maximumLogEventsPerPut; i++ {
|
|
@@ -945,7 +1053,9 @@ func TestCollectBatchMaxTotalBytes(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
numPayloads := maximumBytesPerPut / (maximumBytesPerEvent + perEventBytes)
|
|
|
// maxline is the maximum line that could be submitted after
|
|
@@ -1024,7 +1134,9 @@ func TestCollectBatchWithDuplicateTimestamps(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- go stream.collectBatch()
|
|
|
+ d := make(chan bool)
|
|
|
+ close(d)
|
|
|
+ go stream.collectBatch(d)
|
|
|
|
|
|
times := maximumLogEventsPerPut
|
|
|
expectedEvents := []*cloudwatchlogs.InputLogEvent{}
|