def testPrimaryBuilderIsSelectedWhenAvailable(self):
    fs = fb.FloatingSet()
    fs.AddPrimary('primary-a')
    fs.AddFloating('floating-a', 'floating-b')
    fnsf = fs.NextSlaveFunc(datetime.timedelta(seconds=10))

    self.builder.set_online_slaves('primary-a', 'floating-a', 'floating-b')

    nsb = fnsf(self.builder, self.builder.slavebuilders)
    self.assertIsNotNone(nsb)
    self.assertEqual(nsb.slave.slavename, 'primary-a')
  def testNoBuilderIsSelectedWhenPrimariesAreOfflineWithinGrace(self):
    fs = fb.FloatingSet()
    fs.AddPrimary('primary-a', 'primary-b')
    fs.AddFloating('floating-a', 'floating-b')
    fnsf = fs.NextSlaveFunc(datetime.timedelta(seconds=10))

    self.now += datetime.timedelta(seconds=30)
    self.builder.set_online_slaves('floating-a')
    self._slaves['primary-b']._set_last_seen(self.now, seconds=-1)

    nsb = fnsf(self.builder, self.builder.slavebuilders)
    self.assertIsNone(nsb)
    self.assertEqual(self.poke_delta, datetime.timedelta(seconds=9))
  def testJustStartedNoPrimariesOnlineWaits(self):
    fs = fb.FloatingSet()
    fs.AddPrimary('primary-a')
    fs.AddFloating('floating-a', 'floating-b')
    fnsf = fs.NextSlaveFunc(datetime.timedelta(seconds=10))

    self.builder.set_online_slaves('floating-a', 'floating-b')

    nsb = fnsf(self.builder, self.builder.slavebuilders)
    self.assertIsNone(nsb)
    self.assertEqual(self.poke_delta, datetime.timedelta(seconds=10))

    self.now += datetime.timedelta(seconds=11)
    nsb = fnsf(self.builder, self.builder.slavebuilders)
    self.assertIsNotNone(nsb)
    self.assertEqual(nsb.slave.slavename, 'floating-a')