schedule_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package schedule
  15. import (
  16. "context"
  17. "testing"
  18. )
  19. func TestFIFOSchedule(t *testing.T) {
  20. s := NewFIFOScheduler()
  21. defer s.Stop()
  22. next := 0
  23. jobCreator := func(i int) Job {
  24. return func(ctx context.Context) {
  25. if next != i {
  26. t.Fatalf("job#%d: got %d, want %d", i, next, i)
  27. }
  28. next = i + 1
  29. }
  30. }
  31. var jobs []Job
  32. for i := 0; i < 100; i++ {
  33. jobs = append(jobs, jobCreator(i))
  34. }
  35. for _, j := range jobs {
  36. s.Schedule(j)
  37. }
  38. s.WaitFinish(100)
  39. if s.Scheduled() != 100 {
  40. t.Errorf("scheduled = %d, want %d", s.Scheduled(), 100)
  41. }
  42. }