import tensorflow as tf

      output = f(tf.constant([[1, 3]]), tf.constant([2]))

      tf.train.start_queue_runners()

      start = datetime.datetime.now()
      session.run(output)
      duration = datetime.datetime.now() - start

      # There should have been a timeout here because only one sample was added
      # and the minimum batch size is 2.
      self.assertLessEqual(.9, duration.total_seconds())
      self.assertGreaterEqual(1.5, duration.total_seconds())

      outputs = [
          f(tf.constant([[1, 3]]), tf.constant([2])),
          f(tf.constant([[1, 3]]), tf.constant([2]))
      ]

      start = datetime.datetime.now()
      (_, batch_size), _ = session.run(outputs)
      duration = datetime.datetime.now() - start

      # The outputs should be executed immediately because two samples are
      # added.
      self.assertGreaterEqual(.5, duration.total_seconds())
      self.assertEqual(2, batch_size)

  def test_maximum_batch_size(self):
    with self.test_session() as session:
      @dynamic_batching.batch_fn_with_options(maximum_batch_size=2)
