import tensorflow as tf


      # 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)
      def f(a, b):
        batch_size = tf.shape(a)[0]
        return a + b, tf.tile([batch_size], [batch_size])

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

      tf.train.start_queue_runners()

      results = session.run(outputs)

      for value, batch_size in results:
        self.assertEqual(3, value)
        self.assertGreaterEqual(2, batch_size)
