| id | time-freezing | ||||
|---|---|---|---|---|---|
| title | Time Freezing | ||||
| sidebar_label | Time Freezing | ||||
| tags |
|
||||
| keywords |
|
import ProductTier from '@site/src/components/ProductTier';
While making tests, time-sensitive objects like JWT tokens are a challenge as they expire, leading to test failures. This increases the maintenance effort of test suites and also impacts reliability.
With Keploy Cloud users will be able to freeze/rollback the time in every test run, back to when the test case was recorded.
This allows developers to ensure time-sensitive objects don’t expire or change, making tests consistent and more reliable.
For native Linux, Windows(WSL) environments, simply add the --freezeTime flag when running your tests, like so:
keploy test -c "<appCmd>" --freezeTimeVoila! Your tests will now run with time freezing enabled.
For Docker-based applications, you'll need to make a few adjustments to your Dockerfile to utilize this feature:
- First, check your system architecture
uname -a- Download the the appropriate time freeze agent for your architecture & set the
LD_PRELOADEnvironment Variable in your Dockerfile
Note: Time freezing is only supported till go 1.22.x version.
# Download the time freeze agent
ADD https://keploy-enterprise.s3.us-west-2.amazonaws.com/releases/latest/assets/go_freeze_time_amd64 /lib/keploy/go_freeze_time_amd64
# set suitable permissions
RUN chmod +x /lib/keploy/go_freeze_time_amd64
# run the binary
RUN /lib/keploy/go_freeze_time_amd64
# build your binary with fake time (during test mode)
RUN go build -tags=faketime <your_main_file>
OR
# Download the time freeze agent
ADD https://keploy-enterprise.s3.us-west-2.amazonaws.com/releases/latest/assets/go_freeze_time_arm64 /lib/keploy/go_freeze_time_arm64
# set suitable permissions
RUN chmod +x /lib/keploy/go_freeze_time_arm64
# run the binary
RUN /lib/keploy/go_freeze_time_arm64
# build your binary with fake time (during test mode)
RUN go build -tags=faketime <your_main_file>-
Only Add
faketimetag to your build script during Test MODE -
Re-Build your Docker image.
-
Now add the
--freeze-timeflag when running your tests with Keploy, like so:
keploy test -c "<appCmd>" --freeze-timeVoila! Your tests will now run with time freezing enabled.
# Download the time freeze agent
ADD https://keploy-enterprise.s3.us-west-2.amazonaws.com/releases/latest/assets/freeze_time_amd64.so /lib/keploy/freeze_time_amd64.so
#set suitable permissions
RUN chmod +x /lib/keploy/freeze_time_amd64.so
# Set LD_PRELOAD environment variable to use freeze_time_amd64.so
ENV LD_PRELOAD=/lib/keploy/freeze_time_amd64.soOR
# Download the time freeze agent
ADD https://keploy-enterprise.s3.us-west-2.amazonaws.com/releases/latest/assets/freeze_time_arm64.so /lib/keploy/freeze_time_arm64.so
#set suitable permissions
RUN chmod +x /lib/keploy/freeze_time_arm64.so
# Set LD_PRELOAD environment variable to use freeze_time_arm64.so
ENV LD_PRELOAD=/lib/keploy/freeze_time_arm64.so- Re-Build your Docker image.
- Now add the
--freeze-timeflag when running your tests with Keploy, like so:
keploy test -c "<appCmd>" --freeze-timeVoila! Your tests will now run with time freezing enabled.