@@ -366,7 +366,11 @@ func TestCleanupExistingBackups(t *testing.T) {
366
366
367
367
newFakeTime ()
368
368
369
- b2 := []byte ("foooooo!" )
369
+ // Don't write enough to trigger a rotate or there is
370
+ // a race between whether or not there is one notification
371
+ // or two depending on how far through the millRunOnce method
372
+ // gets before the Write method calls rotate.
373
+ b2 := []byte ("foo" )
370
374
n , err := l .Write (b2 )
371
375
isNil (err , t )
372
376
equals (len (b2 ), n , t )
@@ -631,6 +635,55 @@ func TestCompressOnRotate(t *testing.T) {
631
635
fileCount (dir , 2 , t )
632
636
}
633
637
638
+ func TestCompressOnResume (t * testing.T ) {
639
+ currentTime = fakeTime
640
+ megabyte = 1
641
+
642
+ dir := makeTempDir ("TestCompressOnResume" , t )
643
+ defer os .RemoveAll (dir )
644
+
645
+ notify := make (chan struct {})
646
+ filename := logFile (dir )
647
+ l := & Logger {
648
+ Compress : true ,
649
+ Filename : filename ,
650
+ MaxSize : 10 ,
651
+ notifyCompressed : notify ,
652
+ }
653
+ defer l .Close ()
654
+
655
+ // Create a backup file and empty "compressed" file.
656
+ filename2 := backupFile (dir )
657
+ b := []byte ("foo!" )
658
+ err := ioutil .WriteFile (filename2 , b , 0644 )
659
+ isNil (err , t )
660
+ err = ioutil .WriteFile (filename2 + compressSuffix , []byte {}, 0644 )
661
+ isNil (err , t )
662
+
663
+ newFakeTime ()
664
+
665
+ b2 := []byte ("boo!" )
666
+ n , err := l .Write (b2 )
667
+ isNil (err , t )
668
+ equals (len (b2 ), n , t )
669
+ existsWithContent (filename , b2 , t )
670
+
671
+ waitForNotify (notify , t )
672
+
673
+ // The write should have started the compression - a compressed version of
674
+ // the log file should now exist and the original should have been removed.
675
+ bc := new (bytes.Buffer )
676
+ gz := gzip .NewWriter (bc )
677
+ _ , err = gz .Write (b )
678
+ isNil (err , t )
679
+ err = gz .Close ()
680
+ isNil (err , t )
681
+ existsWithContent (filename2 + compressSuffix , bc .Bytes (), t )
682
+ notExist (filename2 , t )
683
+
684
+ fileCount (dir , 2 , t )
685
+ }
686
+
634
687
func TestJson (t * testing.T ) {
635
688
data := []byte (`
636
689
{
0 commit comments