Ejemplo n.º 1
0
func TestOneStageAbortAfterOne(t *testing.T) {
	p := pipeline.New()
	generator := &AbortableGenerator{}
	generator.QuitChan = make(chan struct{})
	p.SetGenerator(generator)

	stage := &CountingStage{}
	p.AddStage(stage)

	go func() {
		if p.Abort() != nil {
			t.Errorf("expected p.Abort() == nil")
		}

	}()

	err := p.Run()
	if err != nil {
		t.Errorf(`error should be nil`)
	}

	if generator.NextCount != 2 {
		t.Errorf("expected generator.NextCount == 2")
	}

	if generator.AbortCount != 1 {
		t.Errorf("expected generator.AbortCount == 1")
	}

	if stage.ProcessCount != 1 {
		t.Errorf("expected stage.ProcessCount == 1")
	}
}
Ejemplo n.º 2
0
func TestOneStageCountToTen(t *testing.T) {
	p := pipeline.New()
	generator := &CountsToTenGenerator{}
	p.SetGenerator(generator)

	stage1 := &CountingStage{}

	stage2 := &ConcurrentStage{}
	stage2.Waiter = &sync.WaitGroup{}
	stage2.Waiter.Add(10)

	p.AddStage(stage1, stage2)

	err := p.Run()
	if err != nil {
		t.Errorf(`error should be nil`)
	}

	if generator.NextCount != 11 {
		t.Errorf("expected generator.NextCount == 11")
	}

	if stage1.ProcessCount != 10 {
		t.Errorf("expected stage1.ProcessCount == 10")
	}

	if stage2.ProcessCount != 10 {
		t.Errorf("expected stage2.ProcessCount == 10")
	}
}
Ejemplo n.º 3
0
func TestNoGenerator(t *testing.T) {
	p := pipeline.New()

	err := p.Run()

	fmt.Println(err)

	if err != pipeline.ErrNilGenerator {
		t.Errorf(`the pipeline generator should be nil`)
	}

	err = p.Abort()
	if err != pipeline.ErrNilGenerator {
		t.Errorf(`the pipeline generator should be nil`)
	}
}
Ejemplo n.º 4
0
func TestOneStageNoJobs(t *testing.T) {
	p := pipeline.New()
	generator := &EmptyGenerator{}
	p.SetGenerator(generator)

	stage := &CountingStage{}
	p.AddStage(stage)

	err := p.Run()
	if err != nil {
		t.Errorf(`error should be nil`)
	}

	if generator.NextCount != 1 {
		t.Errorf("expected generator.NextCount == 1")
	}

	if generator.AbortCount != 0 {
		t.Errorf("expected generator.AbortCount == 0")
	}

	if stage.ProcessCount != 0 {
		t.Errorf("expected stage.ProcessCount == 0")
	}

	if p.Abort() != nil {
		t.Errorf("expected p.Abort() == nil")
	}

	if generator.NextCount != 1 {
		t.Errorf("expected generator.NextCount == 1")
	}

	if generator.AbortCount != 1 {
		t.Errorf("expected generator.AbortCount == 1")
	}

	if stage.ProcessCount != 0 {
		t.Errorf("expected stage.ProcessCount == 0")
	}
}
Ejemplo n.º 5
0
func TestNoStages(t *testing.T) {
	p := pipeline.New()
	generator := &EmptyGenerator{}
	p.SetGenerator(generator)

	err := p.Run()
	if err == nil {
		t.Errorf(`error should not be nil`)
	}

	if err != pipeline.ErrNoStages {
		t.Errorf(`the pipeline should have no stages`)
	}

	if generator.NextCount != 0 {
		t.Errorf("expected generator.NextCount == 0")
	}

	if generator.AbortCount != 0 {
		t.Errorf("expected generator.AbortCount == 0")
	}
}