// We've tested the functionality of run() already as it is
// part of NewJob, now just test the panic catching
We've tested the functionality of run() already as it is
part of NewJob, now just test the panic catching
// We ' ve tested the functionality of run () already as it is // part of NewJob now just test the panic catching
func TestJobRunPanic(t *testing.T) {
	wait := make(chan struct{})
	boom := func(ctx context.Context, in rc.Params) (rc.Params, error) {
		sleepJob()
		defer close(wait)
		panic("boom")
	}
	jobs := newJobs()
	job := jobs.NewAsyncJob(boom, rc.Params{})
	<-wait
	runtime.Gosched() 
	for i := uint(0); i < 10; i++ {
		job.mu.Lock()
		e := job.Error
		job.mu.Unlock()
		if e != "" {
			break
		}
		time.Sleep(time.Millisecond << i)
	}
	job.mu.Lock()
	assert.Equal(t, false, job.EndTime.IsZero())
	assert.Equal(t, rc.Params{}, job.Output)
	assert.True(t, job.Duration >= floatSleepTime)
	assert.Contains(t, job.Error, "panic received: boom")
	assert.Equal(t, false, job.Success)
	assert.Equal(t, true, job.Finished)
	job.mu.Unlock()
}
func TestJobRunPanic ( t * testing . T ) { wait := make ( chan struct { } ) boom := func ( ctx context . Context , in rc . Params ) ( rc . Params , error ) { sleepJob ( ) defer close ( wait ) panic ( " " ) } jobs := newJobs ( ) job := jobs . NewAsyncJob ( boom , rc . Params { } ) <- wait runtime . Gosched ( ) for i := uint ( 0 ) ; i < 10 ; i ++ { job . mu . Lock ( ) e := job . Error job . mu . Unlock ( ) if e != " " { break } time . Sleep ( time . Millisecond << i ) } job . mu . Lock ( ) assert . Equal ( t , false , job . EndTime . IsZero ( ) ) assert . Equal ( t , rc . Params { } , job . Output ) assert . True ( t , job . Duration >= floatSleepTime ) assert . Contains ( t , job . Error , " " ) assert . Equal ( t , false , job . Success ) assert . Equal ( t , true , job . Finished ) job . mu . Unlock ( ) }
We've tested the functionality of run() already as it is
part of NewJob, now just test the panic catching
We ' ve tested the functionality of run () already as it is part of NewJob now just test the panic catching
// yield to make sure job is updated // Wait a short time for the panic to propagate