}) Context("when the engine build exists", func() { var realBuild *fakes.FakeBuild BeforeEach(func() { fakeBuildDB.GetBuildReturns(model, true, nil) realBuild = new(fakes.FakeBuild) fakeEngineB.LookupBuildReturns(realBuild, nil) realBuild.ResumeStub = func(lager.Logger) { Expect(fakeBuildDB.LeaseBuildTrackingCallCount()).To(Equal(1)) lockedBuild, interval := fakeBuildDB.LeaseBuildTrackingArgsForCall(0) Expect(lockedBuild).To(Equal(model.ID)) Expect(interval).To(Equal(10 * time.Second)) Expect(fakeLease.BreakCallCount()).To(BeZero()) } }) Context("when listening for aborts succeeds", func() { var ( notifier *dbfakes.FakeNotifier abort chan<- struct{} ) BeforeEach(func() { aborts := make(chan struct{}) abort = aborts
fakeBuildDB.GetBuildReturns(model, nil) }) Context("when the engine build exists", func() { var realBuild *fakes.FakeBuild BeforeEach(func() { fakeBuildDB.GetBuildReturns(model, nil) realBuild = new(fakes.FakeBuild) fakeEngineB.LookupBuildReturns(realBuild, nil) realBuild.ResumeStub = func(lager.Logger) { Ω(fakeLocker.AcquireWriteLockImmediatelyCallCount()).Should(Equal(1)) lockedBuild := fakeLocker.AcquireWriteLockImmediatelyArgsForCall(0) Ω(lockedBuild).Should(Equal([]db.NamedLock{db.BuildTrackingLock(model.ID)})) Ω(fakeLock.ReleaseCallCount()).Should(BeZero()) } }) Context("when listening for aborts succeeds", func() { var ( notifier *dbfakes.FakeNotifier abort chan<- struct{} ) BeforeEach(func() { aborts := make(chan struct{}) abort = aborts
var fakeBuild *enginefakes.FakeBuild var resumed <-chan struct{} var blockForever *sync.WaitGroup BeforeEach(func() { fakeBuild = new(enginefakes.FakeBuild) blockForever = new(sync.WaitGroup) forever := blockForever forever.Add(1) r := make(chan struct{}) resumed = r fakeBuild.ResumeStub = func(lager.Logger) { close(r) forever.Wait() } fakeEngine.CreateBuildReturns(fakeBuild, nil) }) AfterEach(func() { blockForever.Done() }) It("returns 201 Created", func() { Expect(response.StatusCode).To(Equal(http.StatusCreated)) }) It("returns the build", func() { body, err := ioutil.ReadAll(response.Body)