Skip to content

Commit 9af26c2

Browse files
committed
fix unmarshal zero time issue
1 parent c6a691b commit 9af26c2

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

model/job.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ func (ct DBTime) MarshalJSON() ([]byte, error) {
187187

188188
func (ct *DBTime) UnmarshalJSON(b []byte) error {
189189
s := strings.Trim(string(b), "\"")
190-
if s == "null" {
190+
// Handle db null value and zero time
191+
if s == "null" || s == "0001-01-01T00:00:00" {
191192
ct.Time = time.Time{}
192193
return nil
193194
}

queuerJob_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,23 @@ func TestAddJobRunning(t *testing.T) {
102102
assert.NoError(t, err, "GetJob should not return an error")
103103
assert.NotNil(t, queuedJob, "GetJob should return the job that is currently running")
104104

105-
time.Sleep(2 * time.Second)
105+
done := make(chan struct{})
106+
go func() {
107+
job = testQueuer.WaitForJobFinished(job.RID)
108+
assert.NotNil(t, job, "WaitForJobFinished should return the finished job")
109+
assert.Equal(t, model.JobStatusSucceeded, job.Status, "WaitForJobFinished should return job with status Succeeded")
110+
close(done)
111+
}()
112+
113+
outerloop:
114+
for {
115+
select {
116+
case <-done:
117+
break outerloop
118+
case <-time.After(2 * time.Second):
119+
t.Fatal("WaitForJobFinished timed out waiting for job to finish")
120+
}
121+
}
106122

107123
jobNotExisting, err := testQueuer.GetJob(job.RID)
108124
assert.Error(t, err, "GetJob should return an error for ended job")

0 commit comments

Comments
 (0)