Skip to content

Commit

Permalink
fix: Fix deletion
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege committed May 23, 2019
1 parent 55ac5dd commit 28b1bed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestCreateExperiment(t *testing.T) {
mc := managerclientmock.NewMockManagerClient(mockCtrl)
mc.EXPECT().CreateExperimentInDB(gomock.Any()).Return(nil).AnyTimes()
mc.EXPECT().UpdateExperimentStatusInDB(gomock.Any()).Return(nil).AnyTimes()
mc.EXPECT().DeleteExperimentInDB(gomock.Any()).Return(nil).AnyTimes()

mockCtrl2 := gomock.NewController(t)
defer mockCtrl2.Finish()
Expand Down Expand Up @@ -103,8 +104,10 @@ func TestCreateExperiment(t *testing.T) {
}
g.Expect(err).NotTo(gomega.HaveOccurred())
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))

g.Expect(c.Delete(context.TODO(), instance)).NotTo(gomega.HaveOccurred())
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(func() bool {
return errors.IsNotFound(c.Get(context.TODO(),
expectedRequest.NamespacedName, instance))
Expand All @@ -120,6 +123,7 @@ func TestReconcileExperiment(t *testing.T) {
mc := managerclientmock.NewMockManagerClient(mockCtrl)
mc.EXPECT().CreateExperimentInDB(gomock.Any()).Return(nil).AnyTimes()
mc.EXPECT().UpdateExperimentStatusInDB(gomock.Any()).Return(nil).AnyTimes()
mc.EXPECT().DeleteExperimentInDB(gomock.Any()).Return(nil).AnyTimes()

mockCtrl2 := gomock.NewController(t)
defer mockCtrl2.Finish()
Expand Down Expand Up @@ -238,6 +242,10 @@ spec:
return
}
g.Expect(err).NotTo(gomega.HaveOccurred())
// We have 4 reconcile requests to finish the process.
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))

trials := &trialsv1alpha2.TrialList{}
Expand All @@ -253,6 +261,7 @@ spec:
Should(gomega.Equal(1))

g.Expect(c.Delete(context.TODO(), instance)).NotTo(gomega.HaveOccurred())
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(func() bool {
return errors.IsNotFound(c.Get(context.TODO(),
expectedRequest.NamespacedName, instance))
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/v1alpha2/experiment/experiment_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (r *ReconcileExperiment) createTrialInstance(expInstance *experimentsv1alph

func (r *ReconcileExperiment) updateFinalizers(instance *experimentsv1alpha2.Experiment, finalizers []string) (reconcile.Result, error) {
logger := log.WithValues("Experiment", types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace})
if instance.GetDeletionTimestamp() != nil {
if !instance.ObjectMeta.DeletionTimestamp.IsZero() {
if err := r.DeleteExperimentInDB(instance); err != nil {
logger.Error(err, "Fail to delete data in DB")
return reconcile.Result{}, err
Expand Down

0 comments on commit 28b1bed

Please sign in to comment.