schedule_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2016 CoreOS, Inc.
  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. "testing"
  17. "github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
  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", 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. }