Skip to content

Inaccurate timing with a very fast clock #66

@knbx

Description

@knbx

Hi there

I really like this library, so I thought I'd mention some weird behaviour I encountered while unit testing.

I set my clock rate at x100 to speed everything up during tests, but noticed some inaccuracies while doing this. Maybe this is just an example of #42 ?

	var cancels: [AnyCancellable] = []
	let fixedStart = Clocks.system.nextHour().firstInstant
	let fastClock = Clocks.custom(startingFrom: fixedStart, rate: 100)

	fastClock
		.chime(at: fastClock.thisSecond() + .seconds(10))
		.sink { _ in
			print("chimed at \(fastClock.now().date)")
		}
		.store(in: &cancels)

	fastClock
		.chime(at: fastClock.thisSecond() + .seconds(17))
		.sink { _ in
			print("chimed at \(fastClock.now().date)")
		}
		.store(in: &cancels)

	//        chimed at 2023-08-21 12:00:10 +0000
	//        chimed at 2023-08-21 12:00:47 +0000

The first chime works as expected, but for any value above 17 'seconds' the timing is off.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions