             XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
         }
 
-        let expect = expectation(description: "Is cancelling RepatedTask")
-        let group = DispatchGroup()
+        let hasFiredGroup = DispatchGroup()
+        let isCancelledGroup = DispatchGroup()
         let loop = eventLoopGroup.next()
-        group.enter()
+        hasFiredGroup.enter()
+        isCancelledGroup.enter()
         var isAllowedToFire = true // read/write only on `loop`
         var hasFired = false // read/write only on `loop`
         let repeatedTask = loop.scheduleRepeatedTask(initialDelay: initialDelay, delay: delay) { (_: RepeatedTask) -> Void in

            if initialValue == 0 {
                XCTAssertTrue(NIODeadline.now() - nanos >= initialDelay)
            } else if initialValue == count {
                expect.fulfill()
                repeatedTask.cancel()
            }
        }

        waitForExpectations(timeout: 1) { error in
            XCTAssertNil(error)
            XCTAssertEqual(counter.load(), count + 1)
            XCTAssertTrue(NIODeadline.now() - nanos >= initialDelay + Int64(count) * delay)
        }
    }

    public func testScheduledTaskThatIsImmediatelyCancelledNeverFires() throws {

                // we can only do this once as we can only leave the DispatchGroup once but we might lose a race and
                // the timer might fire more than once (until `shouldNoLongerFire` becomes true).
                hasFired = true
                hasFiredGroup.leave()
            }
            XCTAssertTrue(isAllowedToFire)
        }
        hasFiredGroup.notify(queue: DispatchQueue.global()) {
            repeatedTask.cancel()
            loop.execute {
                // only now do we know that the `cancel` must have gone through
                isAllowedToFire = false
                isCancelledGroup.leave()
            }
        }

        hasFiredGroup.wait()
        XCTAssertTrue(NIODeadline.now() - nanos >= initialDelay)
        isCancelledGroup.wait()
    }

    public func testScheduleRepeatedTaskToNotRetainRepeatedTask() throws {
