| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "math/rand" | 9 "math/rand" |
| 10 "net/http" | 10 "net/http" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 func TestTaskQueue(t *testing.T) { | 24 func TestTaskQueue(t *testing.T) { |
| 25 t.Parallel() | 25 t.Parallel() |
| 26 | 26 |
| 27 Convey("TaskQueue", t, func() { | 27 Convey("TaskQueue", t, func() { |
| 28 now := time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC) | 28 now := time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC) |
| 29 c, tc := testclock.UseTime(context.Background(), now) | 29 c, tc := testclock.UseTime(context.Background(), now) |
| 30 c = mathrand.Set(c, rand.New(rand.NewSource(clock.Now(c).UnixNan
o()))) | 30 c = mathrand.Set(c, rand.New(rand.NewSource(clock.Now(c).UnixNan
o()))) |
| 31 c = Use(c) | 31 c = Use(c) |
| 32 | 32 |
| 33 tq := tqS.Get(c) | 33 tq := tqS.Get(c) |
| 34 » » tqt := tq.Raw().Testable() | 34 » » tqt := tq.Testable() |
| 35 So(tqt, ShouldNotBeNil) | 35 So(tqt, ShouldNotBeNil) |
| 36 | 36 |
| 37 So(tq, ShouldNotBeNil) | 37 So(tq, ShouldNotBeNil) |
| 38 | 38 |
| 39 Convey("implements TQMultiReadWriter", func() { | 39 Convey("implements TQMultiReadWriter", func() { |
| 40 Convey("Add", func() { | 40 Convey("Add", func() { |
| 41 t := tq.NewTask("/hello/world") | 41 t := tq.NewTask("/hello/world") |
| 42 | 42 |
| 43 Convey("works", func() { | 43 Convey("works", func() { |
| 44 t.Delay = 4 * time.Second | 44 t.Delay = 4 * time.Second |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 So(tqt.GetTransactionTasks()["default"],
ShouldBeNil) | 253 So(tqt.GetTransactionTasks()["default"],
ShouldBeNil) |
| 254 return nil | 254 return nil |
| 255 }, nil) | 255 }, nil) |
| 256 }) | 256 }) |
| 257 | 257 |
| 258 Convey("can add a new task", func() { | 258 Convey("can add a new task", func() { |
| 259 t3 := &tqS.Task{Path: "/sandwitch/victory"} | 259 t3 := &tqS.Task{Path: "/sandwitch/victory"} |
| 260 | 260 |
| 261 err := dsS.Get(c).RunInTransaction(func(c contex
t.Context) error { | 261 err := dsS.Get(c).RunInTransaction(func(c contex
t.Context) error { |
| 262 tq := tqS.Get(c) | 262 tq := tqS.Get(c) |
| 263 » » » » » tqt := tq.Raw().Testable() | 263 » » » » » tqt := tq.Testable() |
| 264 | 264 |
| 265 So(tq.Add(t3, ""), ShouldBeNil) | 265 So(tq.Add(t3, ""), ShouldBeNil) |
| 266 So(t3.Name, ShouldEqual, "") | 266 So(t3.Name, ShouldEqual, "") |
| 267 | 267 |
| 268 So(tqt.GetScheduledTasks()["default"][t.
Name], ShouldResemble, t) | 268 So(tqt.GetScheduledTasks()["default"][t.
Name], ShouldResemble, t) |
| 269 So(tqt.GetTombstonedTasks()["default"][t
2.Name], ShouldResemble, t2) | 269 So(tqt.GetTombstonedTasks()["default"][t
2.Name], ShouldResemble, t2) |
| 270 So(tqt.GetTransactionTasks()["default"][
0], ShouldResemble, t3) | 270 So(tqt.GetTransactionTasks()["default"][
0], ShouldResemble, t3) |
| 271 return nil | 271 return nil |
| 272 }, nil) | 272 }, nil) |
| 273 So(err, ShouldBeNil) | 273 So(err, ShouldBeNil) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 285 So(tqt.GetTransactionTasks()["default"], ShouldB
eNil) | 285 So(tqt.GetTransactionTasks()["default"], ShouldB
eNil) |
| 286 }) | 286 }) |
| 287 | 287 |
| 288 Convey("can add a new task (but reset the state in a tes
t)", func() { | 288 Convey("can add a new task (but reset the state in a tes
t)", func() { |
| 289 t3 := &tqS.Task{Path: "/sandwitch/victory"} | 289 t3 := &tqS.Task{Path: "/sandwitch/victory"} |
| 290 | 290 |
| 291 ttq := tqS.Interface(nil) | 291 ttq := tqS.Interface(nil) |
| 292 | 292 |
| 293 dsS.Get(c).RunInTransaction(func(c context.Conte
xt) error { | 293 dsS.Get(c).RunInTransaction(func(c context.Conte
xt) error { |
| 294 ttq = tqS.Get(c) | 294 ttq = tqS.Get(c) |
| 295 » » » » » tqt := ttq.Raw().Testable() | 295 » » » » » tqt := ttq.Testable() |
| 296 | 296 |
| 297 So(ttq.Add(t3, ""), ShouldBeNil) | 297 So(ttq.Add(t3, ""), ShouldBeNil) |
| 298 | 298 |
| 299 So(tqt.GetScheduledTasks()["default"][t.
Name], ShouldResemble, t) | 299 So(tqt.GetScheduledTasks()["default"][t.
Name], ShouldResemble, t) |
| 300 So(tqt.GetTombstonedTasks()["default"][t
2.Name], ShouldResemble, t2) | 300 So(tqt.GetTombstonedTasks()["default"][t
2.Name], ShouldResemble, t2) |
| 301 So(tqt.GetTransactionTasks()["default"][
0], ShouldResemble, t3) | 301 So(tqt.GetTransactionTasks()["default"][
0], ShouldResemble, t3) |
| 302 | 302 |
| 303 tqt.ResetTasks() | 303 tqt.ResetTasks() |
| 304 | 304 |
| 305 So(len(tqt.GetScheduledTasks()["default"
]), ShouldEqual, 0) | 305 So(len(tqt.GetScheduledTasks()["default"
]), ShouldEqual, 0) |
| 306 So(len(tqt.GetTombstonedTasks()["default
"]), ShouldEqual, 0) | 306 So(len(tqt.GetTombstonedTasks()["default
"]), ShouldEqual, 0) |
| 307 So(len(tqt.GetTransactionTasks()["defaul
t"]), ShouldEqual, 0) | 307 So(len(tqt.GetTransactionTasks()["defaul
t"]), ShouldEqual, 0) |
| 308 | 308 |
| 309 return nil | 309 return nil |
| 310 }, nil) | 310 }, nil) |
| 311 | 311 |
| 312 So(len(tqt.GetScheduledTasks()["default"]), Shou
ldEqual, 0) | 312 So(len(tqt.GetScheduledTasks()["default"]), Shou
ldEqual, 0) |
| 313 So(len(tqt.GetTombstonedTasks()["default"]), Sho
uldEqual, 0) | 313 So(len(tqt.GetTombstonedTasks()["default"]), Sho
uldEqual, 0) |
| 314 So(len(tqt.GetTransactionTasks()["default"]), Sh
ouldEqual, 0) | 314 So(len(tqt.GetTransactionTasks()["default"]), Sh
ouldEqual, 0) |
| 315 | 315 |
| 316 Convey("and reusing a closed context is bad time
s", func() { | 316 Convey("and reusing a closed context is bad time
s", func() { |
| 317 So(ttq.Add(nil, "").Error(), ShouldConta
inSubstring, "expired") | 317 So(ttq.Add(nil, "").Error(), ShouldConta
inSubstring, "expired") |
| 318 }) | 318 }) |
| 319 }) | 319 }) |
| 320 | 320 |
| 321 Convey("you can AddMulti as well", func() { | 321 Convey("you can AddMulti as well", func() { |
| 322 dsS.Get(c).RunInTransaction(func(c context.Conte
xt) error { | 322 dsS.Get(c).RunInTransaction(func(c context.Conte
xt) error { |
| 323 tq := tqS.Get(c) | 323 tq := tqS.Get(c) |
| 324 » » » » » tqt := tq.Raw().Testable() | 324 » » » » » tqt := tq.Testable() |
| 325 | 325 |
| 326 t.Name = "" | 326 t.Name = "" |
| 327 tasks := []*tqS.Task{t.Duplicate(), t.Du
plicate(), t.Duplicate()} | 327 tasks := []*tqS.Task{t.Duplicate(), t.Du
plicate(), t.Duplicate()} |
| 328 So(tq.AddMulti(tasks, ""), ShouldBeNil) | 328 So(tq.AddMulti(tasks, ""), ShouldBeNil) |
| 329 So(len(tqt.GetScheduledTasks()["default"
]), ShouldEqual, 1) | 329 So(len(tqt.GetScheduledTasks()["default"
]), ShouldEqual, 1) |
| 330 So(len(tqt.GetTransactionTasks()["defaul
t"]), ShouldEqual, 3) | 330 So(len(tqt.GetTransactionTasks()["defaul
t"]), ShouldEqual, 3) |
| 331 return nil | 331 return nil |
| 332 }, nil) | 332 }, nil) |
| 333 So(len(tqt.GetScheduledTasks()["default"]), Shou
ldEqual, 4) | 333 So(len(tqt.GetScheduledTasks()["default"]), Shou
ldEqual, 4) |
| 334 So(len(tqt.GetTransactionTasks()["default"]), Sh
ouldEqual, 0) | 334 So(len(tqt.GetTransactionTasks()["default"]), Sh
ouldEqual, 0) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 }() | 392 }() |
| 393 | 393 |
| 394 So(tqt.GetScheduledTasks()["default"][t.Name], S
houldResemble, t) | 394 So(tqt.GetScheduledTasks()["default"][t.Name], S
houldResemble, t) |
| 395 So(tqt.GetTombstonedTasks()["default"][t2.Name],
ShouldResemble, t2) | 395 So(tqt.GetTombstonedTasks()["default"][t2.Name],
ShouldResemble, t2) |
| 396 So(tqt.GetTransactionTasks()["default"], ShouldB
eNil) | 396 So(tqt.GetTransactionTasks()["default"], ShouldB
eNil) |
| 397 }) | 397 }) |
| 398 | 398 |
| 399 }) | 399 }) |
| 400 }) | 400 }) |
| 401 } | 401 } |
| OLD | NEW |