コード例 #1
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// WhenErrorCoverage provides coverage for the When function.
func (t *RSuite) WhenErrorCoverage() async.R {
	expected := fmt.Errorf("some error")
	w := async.When(async.Done(), func() async.R {
		r, s := async.NewR()
		s.Fail(expected)
		return r
	})

	w1 := async.When(w, func(_ interface{}, err error) async.R {
		if err != expected {
			return async.NewErrorf("Expected executed w.  Got: %v, Want: %v", err, expected)
		}
		return w
	})

	w2 := async.When(w1, func(interface{}) async.R {
		return async.NewErrorf("Expected not executed w1")
	})
	w3 := async.When(w2, func(_ interface{}, err error) async.R {
		if err != expected {
			return async.NewErrorf("Expected executed w.  Got: %v, Want: %v", err, expected)
		}
		return w2
	})

	w4 := async.When(w3, func() async.R {
		return async.NewErrorf("Expected not executed w3")
	})
	return async.When(w4, func(_ interface{}, err error) async.R {
		if err != expected {
			return async.NewErrorf("Expected executed w.  Got: %v, Want: %v", err, expected)
		}
		return async.Done()
	})
}
コード例 #2
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// WhenErrorReturnCoverage provides coverage for the When function.
func (t *RSuite) WhenErrorReturnCoverage() async.R {
	expected := fmt.Errorf("some error")
	w := async.When(async.Done(), func() async.R {
		r, s := async.NewR()
		s.Fail(expected)
		return r
	})

	w1 := async.When(w, func(err error) (interface{}, error) {
		if err != expected {
			return nil, fmt.Errorf("Expected executed w.  Got: %v, Want: %v", err, expected)
		}
		return nil, err
	})

	w2 := async.When(w1, func(err error) error {
		if err != expected {
			return fmt.Errorf("Expected executed w1.  Got: %v, Want: %v", err, expected)
		}
		return err
	})

	return async.When(w2, func(err error) async.R {
		if err != expected {
			return async.NewErrorf("Expected executed w2.  Got: %v, Want: %v", err, expected)
		}
		return async.Done()
	})
}
コード例 #3
0
func (t *TurnRunnerSuite) DoneWhen() async.R {
	done := async.Done()
	return async.When(done, func(err error) async.R {
		if err != nil {
			t.Errorf("Expected Done() to succeeed.  Got: %v, Want: nil", err)
		}

		return async.Done()
	})
}
コード例 #4
0
func (t *TurnRunnerSuite) NewResultSuccess() async.R {
	r, s := async.NewR()
	async.When(async.Done(), func() {
		s.Complete()
	})
	return r
}
コード例 #5
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// NewCoverage provides coverage for the New function.
func (t *RSuite) NewCoverage() async.R {
	r, s := async.NewR()
	s.Complete()
	return async.When(r, func(val interface{}, err error) async.R {
		if err != nil {
			return async.NewErrorf("Expected successful completion.  Got: %v, Want: nil", err)
		}
		return async.Done()
	})
}
コード例 #6
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// NewErrorfCoverage provides coverage for the NewErrorf function.
func (t *RSuite) NewErrorfCoverage() async.R {
	expected := fmt.Errorf("some error")
	r := async.NewErrorf("%v", expected)
	return async.When(r, func(val interface{}, err error) async.R {
		if err.Error() != expected.Error() {
			return async.NewErrorf("Expected error.  Got: %v, Want: %v", err, expected)
		}
		return async.Done()
	})
}
コード例 #7
0
// NewResultForward tests Resolver.Forward().
func (t *TurnRunnerSuite) NewResultForward() async.R {
	expected := fmt.Errorf("some error")
	r, s := async.NewR()
	async.When(async.Done(), func() {
		s.Forward(async.NewError(expected))
	})
	return async.When(r, func(err error) error {
		if err != expected {
			return fmt.Errorf("Got: %v, Want: %v", err, expected)
		}
		return nil
	})
}
コード例 #8
0
func (t *TurnRunnerCoreSuite) Done() {
	log.Infof("Running test %s", base.GetMethodName())
	manager := NewManager(NewUniqueIDGenerator())
	runner := NewTurnRunner(manager)
	tlsRelease := async.SetAmbientRunner(runner)
	defer tlsRelease()

	done := async.Done()
	s := async.InternalUseOnlyGetResolver(done.ResultT).(*turnResolver)
	if !s.isResolved() {
		t.Errorf("Expected Done() to be resolved.  Got: %v, Want: resolved", done)
	}
}
コード例 #9
0
func (t *TurnRunnerCoreSuite) OneTurn() {
	manager := NewManager(NewUniqueIDGenerator())
	runner := NewTurnRunner(manager)
	tlsRelease := async.SetAmbientRunner(runner)
	defer tlsRelease()

	done := make(chan struct{}, 0)
	async.New(func() async.R {
		close(done)
		return async.Done()
	})
	manager.runOneLoop()
	<-done
}
コード例 #10
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// WhenCoverage provides coverage for the When function.
func (t *RSuite) WhenCoverage() async.R {
	w := async.When(async.Done(), func(val interface{}, err error) async.R {
		r, s := async.NewR()
		s.Complete()
		return r
	})

	// Verify full signature.
	expected := interface{}(nil)
	w1 := async.When(w, func(val interface{}, err error) async.R {
		if err != nil {
			return async.NewErrorf("Expected success w1.  Got: %v, Want: nil", err)
		}
		if val != expected {
			return async.NewErrorf("Expected value w1.  Got: %v, Want: %v", val, expected)
		}
		return w
	})

	// Verify just error.
	w2 := async.When(w1, func(err error) async.R {
		if err != nil {
			return async.NewErrorf("Expected success w2.  Got: %v, Want: nil", err)
		}
		return w1
	})

	// Verify just value.
	w3 := async.When(w2, func(val interface{}) async.R {
		if val != expected {
			return async.NewErrorf("Expected value w3.  Got: %v, Want: %v", val, expected)
		}
		return w2
	})

	// Verify neither value nor error.
	didRun := false
	w4 := async.When(w3, func() async.R {
		didRun = true
		return w3
	})
	return async.When(w4, func() async.R {
		if !didRun {
			return async.NewErrorf("Expected executed w4.  Got: %v, Want: true", didRun)
		}
		return w4
	})
}
コード例 #11
0
// ResolveCoverage tests Resolver.Resolve().
func (t *TurnRunnerSuite) ResolveCoverage() async.R {
	r, s := async.NewR()
	async.When(async.Done(), func() {
		s.Resolve(nil)
	})

	expected := fmt.Errorf("some error")
	r2, s2 := async.NewR()
	async.When(r, func() {
		s2.Resolve(expected)
	})
	return async.When(r2, func(err error) error {
		if err != expected {
			return fmt.Errorf("Got: %v, Want: %v", err, expected)
		}
		return nil
	})
}
コード例 #12
0
// WhenCoverage provides coverage for the When function.
func (t *StringRSuite) WhenCoverage() async.R {
	expected := "a test string"
	w := async.WhenString(async.Done(), func() async.StringR {
		r, s := async.NewStringR()
		s.Complete(expected)
		return r
	})

	// Verify that the value was round-tripped.
	return async.When(w, func(val string, err error) error {
		if err != nil {
			return fmt.Errorf("Expected success.  Got: %v, Want: nil", err)
		}
		if val != expected {
			return fmt.Errorf("Expected value.  Got: %v, Want: %v", val, expected)
		}
		return nil
	})
}
コード例 #13
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// FinallyCoverage provides coverage for the Finally function.
func (t *RSuite) FinallyCoverage() async.R {
	expected := fmt.Errorf("some error")
	didRun := false
	r, s := async.NewR()
	s.Fail(expected)
	w := async.Finally(r, func() {
		didRun = true
	})

	// Verify that the value was round-tripped.
	return async.When(w, func(val interface{}, err error) async.R {
		if !didRun {
			return async.NewErrorf("Expected finally to run.  Got: false, Want: true")
		}
		if err != expected {
			return async.NewErrorf("Expected error.  Got: %v, Want: %v", err, expected)
		}
		if val != nil {
			return async.NewErrorf("Expected error.  Got: %v, Want: nil", val)
		}
		return async.Done()
	})
}
コード例 #14
0
// ForwardCoverage provides coverage for the Forward function.
func (t *StringRSuite) ForwardCoverage() async.R {
	expected := "a test string"
	resolved, s0 := async.NewStringR()
	s0.Complete(expected)

	// Instead of resolving the return result, forward it to an already resolved value.
	w := async.WhenString(async.Done(), func() async.StringR {
		r, s := async.NewStringR()
		s.Forward(resolved)
		return r
	})

	// Verify that the value was round-tripped.
	return async.When(w, func(val string, err error) error {
		if err != nil {
			return fmt.Errorf("Expected success.  Got: %v, Want: nil", err)
		}
		if val != expected {
			return fmt.Errorf("Expected value.  Got: %v, Want: %v", val, expected)
		}
		return nil
	})
}
コード例 #15
0
// AsyncTurn verifies that a parallel turn executed by a Source does run, and that its resolution is
// reflected correctly on the main turn queue.
func (t *TurnSourceSuite) AsyncTurn() async.R {
	src := turns.NewTurnSource()

	syncPoint1 := make(chan struct{}, 0)
	syncPoint2 := make(chan struct{}, 0)

	// Create a truly parallel turn.
	r := src.New(func() error {
		t.Infof("Beginning async turn.")

		// produce sync point 1.
		close(syncPoint1)

		// wait for sync point 2.
		<-syncPoint2

		return nil
	})

	// Create a coop-turn to provide the sync point.
	async.New(func() async.R {
		t.Infof("Beginning coop turn that provides sync point.")
		// Wait for both parallel and coop turns to have started.
		<-syncPoint1

		// Completed the parallel turn.
		close(syncPoint2)
		return async.Done()
	})

	// Cleanup the source.
	return async.Finally(r, func() {
		// Destroy the TurnSource since we don't need it anymore.
		src.Close()
	})
}
コード例 #16
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// WhenReturnCoverage provides coverage for the When function.
func (t *RSuite) WhenReturnCoverage() async.R {
	w := async.When(async.Done(), func() async.R {
		r, s := async.NewR()
		s.Complete()
		return r
	})

	w1 := async.When(w, func() (interface{}, error) {
		return nil, nil
	})

	w2 := async.When(w1, func() error {
		return nil
	})

	w3 := async.When(w2, func() interface{} {
		return nil
	})

	w4 := async.When(w3, func() {
	})

	return w4
}
コード例 #17
0
func (t *TurnSuiteSuite) VerifyAsyncMethodsAllowed() async.R {
	return async.Done()
}
コード例 #18
0
func (t *TurnRunnerSuite) Done() async.R {
	return async.Done()
}