diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0da73f06..d02d8006 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: deno-version: ${{ matrix.deno-version }} - name: Set NATS Server Version - run: echo "NATS_VERSION=v2.10.12" >> $GITHUB_ENV + run: echo "NATS_VERSION=v2.10.14" >> $GITHUB_ENV # this here because dns seems to be wedged on gha # - name: Add hosts to /etc/hosts diff --git a/jetstream/consumer.ts b/jetstream/consumer.ts index 4bccf43a..e39b283a 100644 --- a/jetstream/consumer.ts +++ b/jetstream/consumer.ts @@ -16,12 +16,13 @@ import { backoff, deferred, delay, + nanos, Timeout, timeout, } from "../nats-base-client/util.ts"; import { ConsumerAPI, ConsumerAPIImpl } from "./jsmconsumer_api.ts"; import { nuid } from "../nats-base-client/nuid.ts"; -import { isHeartbeatMsg, nanos } from "./jsutil.ts"; +import { isHeartbeatMsg } from "./jsutil.ts"; import { QueuedIteratorImpl } from "../nats-base-client/queued_iterator.ts"; import { createInbox, diff --git a/jetstream/internal_mod.ts b/jetstream/internal_mod.ts index f6832057..7a7b4bb0 100644 --- a/jetstream/internal_mod.ts +++ b/jetstream/internal_mod.ts @@ -1,5 +1,5 @@ /* - * Copyright 2023 The NATS Authors + * Copyright 2023-2024 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,13 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { - checkJsError, - isFlowControlMsg, - isHeartbeatMsg, - millis, - nanos, -} from "./jsutil.ts"; +export { checkJsError, isFlowControlMsg, isHeartbeatMsg } from "./jsutil.ts"; export { AdvisoryKind, diff --git a/jetstream/jsapi_types.ts b/jetstream/jsapi_types.ts index 49781875..ab6fe6e1 100644 --- a/jetstream/jsapi_types.ts +++ b/jetstream/jsapi_types.ts @@ -1,5 +1,5 @@ /* - * Copyright 2023 The NATS Authors + * Copyright 2023-2024 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -14,7 +14,8 @@ */ import { ApiError, Nanos } from "../nats-base-client/core.ts"; -import { nanos } from "./jsutil.ts"; + +import { nanos } from "../nats-base-client/util.ts"; export interface ApiPaged { total: number; diff --git a/jetstream/jsclient.ts b/jetstream/jsclient.ts index b8a7d262..f5c681f2 100644 --- a/jetstream/jsclient.ts +++ b/jetstream/jsclient.ts @@ -21,8 +21,6 @@ import { isHeartbeatMsg, isTerminal409, Js409Errors, - millis, - nanos, newJsErrorMsg, validateDurableName, validateStreamName, @@ -39,7 +37,13 @@ import { IngestionFilterFnResult, QueuedIteratorImpl, } from "../nats-base-client/queued_iterator.ts"; -import { delay, Timeout, timeout } from "../nats-base-client/util.ts"; +import { + delay, + millis, + nanos, + Timeout, + timeout, +} from "../nats-base-client/util.ts"; import { headers } from "../nats-base-client/headers.ts"; import { Bucket } from "./kv.ts"; import { Feature } from "../nats-base-client/semver.ts"; diff --git a/jetstream/jsmsg.ts b/jetstream/jsmsg.ts index 2f92a901..10bcdcf4 100644 --- a/jetstream/jsmsg.ts +++ b/jetstream/jsmsg.ts @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 The NATS Authors + * Copyright 2021-2024 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,10 +17,10 @@ import { JSONCodec, StringCodec } from "../nats-base-client/codec.ts"; import { MsgImpl } from "../nats-base-client/msg.ts"; import { ProtocolHandler } from "../nats-base-client/protocol.ts"; import { RequestOne } from "../nats-base-client/request.ts"; -import { nanos } from "./jsutil.ts"; import { Msg, MsgHdrs, RequestOptions } from "../nats-base-client/core.ts"; import { DeliveryInfo, PullOptions } from "./jsapi_types.ts"; import { deferred } from "../nats-base-client/mod.ts"; +import { nanos } from "../nats-base-client/util.ts"; export const ACK = Uint8Array.of(43, 65, 67, 75); const NAK = Uint8Array.of(45, 78, 65, 75); diff --git a/jetstream/jsutil.ts b/jetstream/jsutil.ts index 7a47e13c..9aa199a2 100644 --- a/jetstream/jsutil.ts +++ b/jetstream/jsutil.ts @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 The NATS Authors + * Copyright 2021-2024 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,7 +19,6 @@ import { MsgImpl } from "../nats-base-client/msg.ts"; import { ErrorCode, Msg, - Nanos, NatsError, Publisher, } from "../nats-base-client/core.ts"; @@ -89,22 +88,6 @@ export function validName(name = ""): string { return ""; } -/** - * Converts the specified millis into Nanos - * @param millis - */ -export function nanos(millis: number): Nanos { - return millis * 1000000; -} - -/** - * Convert the specified Nanos into millis - * @param ns - */ -export function millis(ns: Nanos) { - return Math.floor(ns / 1000000); -} - /** * Returns true if the message is a flow control message * @param msg diff --git a/jetstream/kv.ts b/jetstream/kv.ts index 0dac7e04..6b535554 100644 --- a/jetstream/kv.ts +++ b/jetstream/kv.ts @@ -21,7 +21,6 @@ import { Payload, QueuedIterator, } from "../nats-base-client/core.ts"; -import { millis, nanos } from "./jsutil.ts"; import { QueuedIteratorImpl } from "../nats-base-client/queued_iterator.ts"; import { headers } from "../nats-base-client/headers.ts"; import { @@ -47,7 +46,7 @@ import { StoredMsg, } from "./types.ts"; import { compare, Feature, parseSemVer } from "../nats-base-client/semver.ts"; -import { deferred } from "../nats-base-client/util.ts"; +import { deferred, millis, nanos } from "../nats-base-client/util.ts"; import { Empty } from "../nats-base-client/encoders.ts"; import { AckPolicy, diff --git a/jetstream/mod.ts b/jetstream/mod.ts index 2d9a92a8..fa1b5f35 100644 --- a/jetstream/mod.ts +++ b/jetstream/mod.ts @@ -1,5 +1,5 @@ /* - * Copyright 2023 The NATS Authors + * Copyright 2023-2024 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,8 +16,6 @@ export { checkJsError, isFlowControlMsg, isHeartbeatMsg, - millis, - nanos, } from "./internal_mod.ts"; export { diff --git a/jetstream/tests/consume_test.ts b/jetstream/tests/consume_test.ts index 1b18b972..9dfe2199 100644 --- a/jetstream/tests/consume_test.ts +++ b/jetstream/tests/consume_test.ts @@ -28,8 +28,12 @@ import { } from "https://deno.land/std@0.221.0/assert/mod.ts"; import { initStream } from "./jstest_util.ts"; import { AckPolicy, DeliverPolicy } from "../jsapi_types.ts"; -import { deadline, deferred, delay } from "../../nats-base-client/util.ts"; -import { nanos } from "../jsutil.ts"; +import { + deadline, + deferred, + delay, + nanos, +} from "../../nats-base-client/util.ts"; import { ConsumerEvents, ConsumerStatus, diff --git a/jetstream/tests/consumers_test.ts b/jetstream/tests/consumers_test.ts index 1213a0a0..2988f7f5 100644 --- a/jetstream/tests/consumers_test.ts +++ b/jetstream/tests/consumers_test.ts @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 The NATS Authors + * Copyright 2022-2024 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,13 +19,12 @@ import { assertRejects, assertStringIncludes, } from "https://deno.land/std@0.221.0/assert/mod.ts"; -import { deferred } from "../../nats-base-client/mod.ts"; +import { deferred, nanos } from "../../nats-base-client/mod.ts"; import { AckPolicy, Consumer, ConsumerMessages, DeliverPolicy, - nanos, PullOptions, } from "../mod.ts"; import { NatsServer } from "../../tests/helpers/launcher.ts"; diff --git a/jetstream/tests/fetch_test.ts b/jetstream/tests/fetch_test.ts index 8e36bdd0..6e21c156 100644 --- a/jetstream/tests/fetch_test.ts +++ b/jetstream/tests/fetch_test.ts @@ -27,8 +27,7 @@ import { } from "https://deno.land/std@0.221.0/assert/mod.ts"; import { Empty } from "../../nats-base-client/encoders.ts"; import { StringCodec } from "../../nats-base-client/codec.ts"; -import { delay } from "../../nats-base-client/util.ts"; -import { nanos } from "../jsutil.ts"; +import { delay, nanos } from "../../nats-base-client/util.ts"; import { NatsConnectionImpl } from "../../nats-base-client/nats.ts"; import { syncIterator } from "../../nats-base-client/core.ts"; import { PullConsumerMessagesImpl } from "../consumer.ts"; diff --git a/jetstream/tests/jetream409_test.ts b/jetstream/tests/jetream409_test.ts index 506a78b3..748fc4cd 100644 --- a/jetstream/tests/jetream409_test.ts +++ b/jetstream/tests/jetream409_test.ts @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 The NATS Authors + * Copyright 2022-2024 The NATS Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,9 +13,10 @@ * limitations under the License. */ -import { Js409Errors, nanos, setMaxWaitingToFail } from "../jsutil.ts"; +import { Js409Errors, setMaxWaitingToFail } from "../jsutil.ts"; import { deferred, + nanos, NatsError, StringCodec, } from "../../nats-base-client/mod.ts"; diff --git a/jetstream/tests/jetstream_pullconsumer_test.ts b/jetstream/tests/jetstream_pullconsumer_test.ts index 2667d7e2..06bc560f 100644 --- a/jetstream/tests/jetstream_pullconsumer_test.ts +++ b/jetstream/tests/jetstream_pullconsumer_test.ts @@ -38,7 +38,7 @@ import { fail, } from "https://deno.land/std@0.221.0/assert/mod.ts"; import { Empty } from "../../nats-base-client/encoders.ts"; -import { checkJsError, nanos } from "../jsutil.ts"; +import { checkJsError } from "../jsutil.ts"; import { JSONCodec, StringCodec } from "../../nats-base-client/codec.ts"; import { consumerOpts, @@ -46,7 +46,7 @@ import { JetStreamSubscriptionInfoable, PubAck, } from "../types.ts"; -import { deferred, delay } from "../../nats-base-client/util.ts"; +import { deferred, delay, nanos } from "../../nats-base-client/util.ts"; import { DebugEvents, ErrorCode, diff --git a/jetstream/tests/jetstream_pushconsumer_test.ts b/jetstream/tests/jetstream_pushconsumer_test.ts index 27be70c8..0546818c 100644 --- a/jetstream/tests/jetstream_pushconsumer_test.ts +++ b/jetstream/tests/jetstream_pushconsumer_test.ts @@ -55,16 +55,11 @@ import { } from "../jsapi_types.ts"; import { JSONCodec, StringCodec } from "../../nats-base-client/codec.ts"; import { Empty } from "../../nats-base-client/encoders.ts"; -import { deferred, delay } from "../../nats-base-client/util.ts"; +import { deferred, delay, nanos } from "../../nats-base-client/util.ts"; import { nuid } from "../../nats-base-client/nuid.ts"; import { JsMsg } from "../jsmsg.ts"; import { connect } from "../../src/connect.ts"; -import { - isFlowControlMsg, - isHeartbeatMsg, - Js409Errors, - nanos, -} from "../jsutil.ts"; +import { isFlowControlMsg, isHeartbeatMsg, Js409Errors } from "../jsutil.ts"; import { JetStreamSubscriptionImpl } from "../jsclient.ts"; Deno.test("jetstream - ephemeral push", async () => { diff --git a/jetstream/tests/jetstream_test.ts b/jetstream/tests/jetstream_test.ts index 66c1cbbb..b8f946ce 100644 --- a/jetstream/tests/jetstream_test.ts +++ b/jetstream/tests/jetstream_test.ts @@ -23,7 +23,6 @@ import { JsHeaders, JsMsg, JsMsgCallback, - nanos, PubAck, RepublishHeaders, RetentionPolicy, @@ -41,6 +40,7 @@ import { ErrorCode, headers, JSONCodec, + nanos, NatsError, nuid, StringCodec, diff --git a/jetstream/tests/jsm_test.ts b/jetstream/tests/jsm_test.ts index 4f962948..d2197043 100644 --- a/jetstream/tests/jsm_test.ts +++ b/jetstream/tests/jsm_test.ts @@ -30,6 +30,7 @@ import { headers, JSONCodec, jwtAuthenticator, + nanos, NatsConnection, NatsError, nkeys, @@ -43,7 +44,6 @@ import { ConsumerInfo, DiscardPolicy, Lister, - nanos, PubAck, RetentionPolicy, StorageType, diff --git a/jetstream/tests/jsmsg_test.ts b/jetstream/tests/jsmsg_test.ts index 0a9d701b..e0d0b416 100644 --- a/jetstream/tests/jsmsg_test.ts +++ b/jetstream/tests/jsmsg_test.ts @@ -23,10 +23,10 @@ import { createInbox, Empty, Msg, + nanos, StorageType, StringCodec, } from "../../src/mod.ts"; -import { nanos } from "../jsutil.ts"; import { JsMsgImpl, parseInfo, toJsMsg } from "../jsmsg.ts"; import { cleanup, diff --git a/jetstream/tests/kv_test.ts b/jetstream/tests/kv_test.ts index b64a23d7..4d63daf7 100644 --- a/jetstream/tests/kv_test.ts +++ b/jetstream/tests/kv_test.ts @@ -19,6 +19,7 @@ import { deferred, delay, Empty, + nanos, NatsConnection, NatsConnectionImpl, nuid, @@ -34,7 +35,6 @@ import { KV, KvEntry, KvOptions, - nanos, StorageType, } from "../mod.ts"; diff --git a/jetstream/tests/next_test.ts b/jetstream/tests/next_test.ts index 67e88802..fb081419 100644 --- a/jetstream/tests/next_test.ts +++ b/jetstream/tests/next_test.ts @@ -24,9 +24,8 @@ import { assertEquals, assertRejects, } from "https://deno.land/std@0.221.0/assert/mod.ts"; -import { nanos } from "../jsutil.ts"; import { NatsConnectionImpl } from "../../nats-base-client/nats.ts"; -import { delay } from "../../nats-base-client/util.ts"; +import { delay, nanos } from "../../nats-base-client/util.ts"; Deno.test("next - basics", async () => { const { ns, nc } = await setup(jetstreamServerConf()); @@ -161,6 +160,7 @@ Deno.test("next - deleted consumer", async () => { const js = nc.jetstream(); const c = await js.consumers.get("A", "a"); + (nc as NatsConnectionImpl).options.debug = true; const exited = assertRejects( () => { return c.next({ expires: 4000 }); @@ -191,7 +191,9 @@ Deno.test("next - stream not found", async () => { const js = nc.jetstream(); const c = await js.consumers.get("A", "a"); + (nc as NatsConnectionImpl).options.debug = true; await jsm.streams.delete("A"); + await delay(1000); await assertRejects( () => { diff --git a/jetstream/types.ts b/jetstream/types.ts index c5719284..4bfc1761 100644 --- a/jetstream/types.ts +++ b/jetstream/types.ts @@ -58,8 +58,9 @@ import { import { JsMsg } from "./jsmsg.ts"; import { BaseApiClient } from "./jsbaseclient_api.ts"; import { ConsumerAPI } from "./jsmconsumer_api.ts"; -import { nanos, validateDurableName } from "./jsutil.ts"; +import { validateDurableName } from "./jsutil.ts"; import { Lister } from "./jslister.ts"; +import { nanos } from "../nats-base-client/util.ts"; /** * The response returned by the JetStream server when a message is added to a stream. diff --git a/nats-base-client/internal_mod.ts b/nats-base-client/internal_mod.ts index 279ac4c6..81b5fe7f 100644 --- a/nats-base-client/internal_mod.ts +++ b/nats-base-client/internal_mod.ts @@ -15,6 +15,8 @@ export { deferred, delay, extend, + millis, + nanos, render, timeout, } from "./util.ts"; diff --git a/nats-base-client/mod.ts b/nats-base-client/mod.ts index 56bb5db3..9096dd00 100644 --- a/nats-base-client/mod.ts +++ b/nats-base-client/mod.ts @@ -17,7 +17,9 @@ export { jwtAuthenticator, Match, Metric, + millis, MsgHdrsImpl, + nanos, NatsError, nkeyAuthenticator, nkeys, diff --git a/nats-base-client/service.ts b/nats-base-client/service.ts index da313f29..af262f45 100644 --- a/nats-base-client/service.ts +++ b/nats-base-client/service.ts @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Deferred, deferred } from "./util.ts"; +import { Deferred, deferred, nanos } from "./util.ts"; import { headers } from "./headers.ts"; import { JSONCodec } from "./codec.ts"; import { nuid } from "./nuid.ts"; import { QueuedIteratorImpl } from "./queued_iterator.ts"; -import { nanos, validateName } from "../jetstream/jsutil.ts"; +import { validateName } from "../jetstream/jsutil.ts"; import { parseSemVer } from "./semver.ts"; import { Empty } from "./encoders.ts"; import { diff --git a/nats-base-client/util.ts b/nats-base-client/util.ts index f3d2ae18..c69fc933 100644 --- a/nats-base-client/util.ts +++ b/nats-base-client/util.ts @@ -14,7 +14,7 @@ */ // deno-lint-ignore-file no-explicit-any import { TD } from "./encoders.ts"; -import { ErrorCode, NatsError } from "./core.ts"; +import { ErrorCode, Nanos, NatsError } from "./core.ts"; export type ValueResult = { isError: false; @@ -285,3 +285,19 @@ export function backoff(policy = [0, 250, 250, 500, 500, 3000, 5000]): Backoff { }, }; } + +/** + * Converts the specified millis into Nanos + * @param millis + */ +export function nanos(millis: number): Nanos { + return millis * 1000000; +} + +/** + * Convert the specified Nanos into millis + * @param ns + */ +export function millis(ns: Nanos) { + return Math.floor(ns / 1000000); +} diff --git a/src/deno_transport.ts b/src/deno_transport.ts index 1287dce5..697bcd5f 100644 --- a/src/deno_transport.ts +++ b/src/deno_transport.ts @@ -156,6 +156,7 @@ export class DenoTransport implements Transport { async startTLS(hostname: string): Promise { const sto = await (this.loadTlsOptions(hostname)); this.conn = await Deno.startTls( + //@ts-ignore: just the conn this.conn, sto, ); diff --git a/tests/auth_test.ts b/tests/auth_test.ts index 3b635d10..ae3e3b44 100644 --- a/tests/auth_test.ts +++ b/tests/auth_test.ts @@ -979,6 +979,8 @@ Deno.test("auth - mux sub ok", async () => { }); await proms; + await Promise.all([nc.flush(), sc.flush()]); + await nc.request("q"); await cleanup(ns, nc, sc); });