Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/natsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ static inline bool nats_StringEquals(const char *s1, const char *s2)
#define NATS_MILLIS_TO_NANOS(d) (((int64_t)d)*(int64_t)1E6)
#define NATS_SECONDS_TO_NANOS(d) (((int64_t)d)*(int64_t)1E9)

#if __STDC_VERSION__ >= 201112L
#define NATS_GLOBAL_STATIC_ASSERT(_cond, _message_as_id) \
_Static_assert(_cond, #_message_as_id)
#else
// for C99 we define explicitly
#define NATS_GLOBAL_STATIC_ASSERT(_cond, _message_as_id) \
typedef char static_assertion_##_message_as_id[(_cond) ? 1 : -1]
#endif

extern int64_t gLockSpinCount;

typedef void (*natsInitOnceCb)(void);
Expand Down
2 changes: 1 addition & 1 deletion src/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static const char *statusText[] = {
"Jetstream Consumer PinID Mismatch",
};

static_assert(NATS_MAX_STATUS_VALUE_ == sizeof(statusText)/sizeof(statusText[0]), "Incorrect array size");
NATS_GLOBAL_STATIC_ASSERT(NATS_MAX_STATUS_VALUE == sizeof(statusText)/sizeof(statusText[0]), Incorrect_array_size);

const char*
natsStatus_GetText(natsStatus s) {
Expand Down
2 changes: 1 addition & 1 deletion src/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ typedef enum
NATS_PIN_ID_MISMATCH, ///< Pin ID sent in the request does not match the currently pinned
/// consumer subscriber ID on the server.

NATS_MAX_STATUS_VALUE_, ///< Maximum status value, this element MUST be the last one
NATS_MAX_STATUS_VALUE, ///< Maximum status value, this element MUST be the last one

} natsStatus;

Expand Down
14 changes: 11 additions & 3 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33802,12 +33802,20 @@ void test_KeyValueDiscardOldToNew(void)
kvStore *kv = NULL;
kvConfig kvc;
natsStatus s;
int ma, mi, up;

JS_SETUP(2, 7, 2);

// We will wait for the INFO in response to CONNECT to arrive before
// changing the server versions.
nats_Sleep(250);

// Change the server version in the connection to
// create as-if we were connecting to a v2.7.1 server.
natsConn_Lock(nc);
ma = nc->srvVersion.ma;
mi = nc->srvVersion.mi;
up = nc->srvVersion.up;
nc->srvVersion.ma = 2;
nc->srvVersion.mi = 7;
nc->srvVersion.up = 1;
Expand All @@ -33821,9 +33829,9 @@ void test_KeyValueDiscardOldToNew(void)

// Now change version to 2.7.2
natsConn_Lock(nc);
nc->srvVersion.ma = 2;
nc->srvVersion.mi = 7;
nc->srvVersion.up = 2;
nc->srvVersion.ma = ma;
nc->srvVersion.mi = mi;
nc->srvVersion.up = up;
natsConn_Unlock(nc);

test("Check discard (old, no auto-update): ");
Expand Down