github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/publisher/combo/fanout_test.go (about)

     1  //go:build unit || !integration
     2  
     3  package combo
     4  
     5  import (
     6  	"fmt"
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/filecoin-project/bacalhau/pkg/model"
    11  )
    12  
    13  var sleepyPublisher = mockPublisher{
    14  	isInstalled:        true,
    15  	publishShardResult: model.StorageSpec{CID: "123"},
    16  	sleepTime:          50 * time.Millisecond,
    17  }
    18  
    19  var uninstalledPublisher = mockPublisher{
    20  	isInstalled:           false,
    21  	publishShardResultErr: fmt.Errorf("not installed"),
    22  	sleepTime:             0,
    23  }
    24  
    25  func TestFanoutPublisher(t *testing.T) {
    26  	runTestCases(t, map[string]comboTestCase{
    27  		"single publisher":                 {NewFanoutPublisher(&healthyPublisher), healthyPublisher},
    28  		"takes first value":                {NewFanoutPublisher(&healthyPublisher, &sleepyPublisher), healthyPublisher},
    29  		"waits for installed":              {NewFanoutPublisher(&uninstalledPublisher, &sleepyPublisher), sleepyPublisher},
    30  		"noone is installed":               {NewFanoutPublisher(&uninstalledPublisher), uninstalledPublisher},
    31  		"waits for good value":             {NewFanoutPublisher(&errorPublisher, &sleepyPublisher), sleepyPublisher},
    32  		"returns error for all":            {NewFanoutPublisher(&errorPublisher, &errorPublisher), errorPublisher},
    33  		"waits for highest priority value": {NewPrioritizedFanoutPublisher(time.Millisecond*100, &sleepyPublisher, &healthyPublisher), sleepyPublisher},
    34  		"only waits for max time":          {NewPrioritizedFanoutPublisher(time.Millisecond*20, &sleepyPublisher, &healthyPublisher), healthyPublisher},
    35  		"waits for unprioritized value":    {NewPrioritizedFanoutPublisher(time.Millisecond*100, &errorPublisher, &sleepyPublisher), sleepyPublisher},
    36  	})
    37  }