Fix timeout encoding test

pull/11866/head
Craig Tiller 8 years ago
parent 50448beab3
commit a1bb6cad29
  1. 2
      src/core/lib/transport/timeout_encoding.c
  2. 13
      test/core/transport/timeout_encoding_test.c

@ -89,7 +89,7 @@ static int is_all_whitespace(const char *p, const char *end) {
}
int grpc_http2_decode_timeout(grpc_slice text, grpc_millis *timeout) {
int32_t x = 0;
grpc_millis x = 0;
const uint8_t *p = GRPC_SLICE_START_PTR(text);
const uint8_t *end = GRPC_SLICE_END_PTR(text);
int have_digit = 0;

@ -25,6 +25,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
#include "src/core/lib/support/murmur_hash.h"
#include "src/core/lib/support/string.h"
#include "test/core/util/test_config.h"
@ -64,10 +65,14 @@ void test_encoding(void) {
static void assert_decodes_as(const char *buffer, grpc_millis expected) {
grpc_millis got;
gpr_log(GPR_INFO, "check decoding '%s'", buffer);
uint32_t hash = gpr_murmur_hash3(buffer, strlen(buffer), 0);
gpr_log(GPR_INFO, "check decoding '%s' (hash=0x%x)", buffer, hash);
GPR_ASSERT(1 == grpc_http2_decode_timeout(
grpc_slice_from_static_string(buffer), &got));
GPR_ASSERT(got == expected);
if (got != expected) {
gpr_log(GPR_ERROR, "got:'%"PRIdPTR"' != expected:'%"PRIdPTR"'", got, expected);
abort();
}
}
void decode_suite(char ext, grpc_millis (*answer)(int64_t x)) {
@ -95,8 +100,8 @@ void decode_suite(char ext, grpc_millis (*answer)(int64_t x)) {
}
}
static grpc_millis millis_from_nanos(int64_t x) { return x / GPR_NS_PER_MS; }
static grpc_millis millis_from_micros(int64_t x) { return x / GPR_US_PER_MS; }
static grpc_millis millis_from_nanos(int64_t x) { return x / GPR_NS_PER_MS + (x % GPR_NS_PER_MS != 0); }
static grpc_millis millis_from_micros(int64_t x) { return x / GPR_US_PER_MS + (x % GPR_US_PER_MS != 0); }
static grpc_millis millis_from_millis(int64_t x) { return x; }
static grpc_millis millis_from_seconds(int64_t x) { return x * GPR_MS_PER_SEC; }
static grpc_millis millis_from_minutes(int64_t x) {

Loading…
Cancel
Save