github.com/opsramp/moby@v1.13.1/restartmanager/restartmanager_test.go (about)

     1  package restartmanager
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/docker/docker/api/types/container"
     8  )
     9  
    10  func TestRestartManagerTimeout(t *testing.T) {
    11  	rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
    12  	should, _, err := rm.ShouldRestart(0, false, 1*time.Second)
    13  	if err != nil {
    14  		t.Fatal(err)
    15  	}
    16  	if !should {
    17  		t.Fatal("container should be restarted")
    18  	}
    19  	if rm.timeout != 100*time.Millisecond {
    20  		t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout)
    21  	}
    22  }
    23  
    24  func TestRestartManagerTimeoutReset(t *testing.T) {
    25  	rm := New(container.RestartPolicy{Name: "always"}, 0).(*restartManager)
    26  	rm.timeout = 5 * time.Second
    27  	_, _, err := rm.ShouldRestart(0, false, 10*time.Second)
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	if rm.timeout != 100*time.Millisecond {
    32  		t.Fatalf("restart manager should have a timeout of 100ms but has %s", rm.timeout)
    33  	}
    34  }