diff --git a/api/api.go b/api/api.go index eaae377..eefa826 100644 --- a/api/api.go +++ b/api/api.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "net/http" - "time" "github.com/kr/pretty" "golang.org/x/exp/slices" @@ -16,7 +15,6 @@ import ( "tier.run/refs" "tier.run/stripe" "tier.run/trweb" - "tier.run/values" ) func init() { @@ -246,7 +244,7 @@ func (h *Handler) serveReport(w http.ResponseWriter, r *http.Request) error { return h.c.ReportUsage(r.Context(), rr.Org, rr.Feature, control.Report{ N: rr.N, - At: values.Coalesce(rr.At, time.Now()), + At: rr.At, Clobber: rr.Clobber, }) } diff --git a/api/api_test.go b/api/api_test.go index 4d6a165..b707d7a 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -406,7 +406,11 @@ func TestTierReport(t *testing.T) { t.Parallel() ctx := context.Background() - tc, _ := newTestClient(t) + tc, cc := newTestClient(t) + + farIntoTheFuture := time.Now().Add(24 * time.Hour) + clock := stroke.NewClock(t, cc.Stripe, t.Name(), farIntoTheFuture) + cc.Clock = clock.ID() pr, err := tc.PushJSON(ctx, []byte(` { @@ -436,14 +440,8 @@ func TestTierReport(t *testing.T) { } if err := tc.ReportUsage(ctx, "org:test", "feature:t", 10, &tier.ReportParams{ - // Report the usage at a time in the near future to avoid - // complaints from Stripe about being too early (e.g. the same - // start time as the current phase) or too late (e.g. > 5mins - // into the future. - // - // If this test becomes flaky, we should use Test Clocks. For - // now, avoid the slowness of the Test Clock API. - At: time.Now().Add(1 * time.Minute), + // Force 'now' at Stripe. + At: time.Time{}, // for 'now' on the server Clobber: false, }); err != nil { diff --git a/client/tier/client.go b/client/tier/client.go index cd298b6..d5aed74 100644 --- a/client/tier/client.go +++ b/client/tier/client.go @@ -239,7 +239,6 @@ func (c *Client) Subscribe(ctx context.Context, org string, featuresAndPlans ... Org: org, Phases: []apitypes.Phase{{Features: featuresAndPlans}}, }) - return err } diff --git a/cmd/tier/tier.go b/cmd/tier/tier.go index 3fe83c6..2d28d41 100644 --- a/cmd/tier/tier.go +++ b/cmd/tier/tier.go @@ -408,7 +408,6 @@ func runTier(cmd string, args []string) (err error) { return err } return tc().ReportUsage(ctx, org, feature, n, &tier.ReportParams{ - At: time.Now(), Clobber: *clobber, }) case "whoami":