def testPeriodically(self):
    """Tests that a function is called exactly every `period` steps."""
    target = tf.Variable(0)
    period = 3

    periodic_update = periodic_ops.periodically(
        body=lambda: target.assign_add(1).op, period=period)

    with self.test_session() as sess:
      sess.run(tf.global_variables_initializer())
      desired_values = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4]
      for desired_value in desired_values:
        sess.run(periodic_update)
        result = sess.run(target)
        self.assertEqual(desired_value, result)
Tests that a function is called exactly every `period` steps.
trfl/periodic_ops_test.py