gRP C: 14 недоступно: не удалось подключиться ко всем адресам - PullRequest
0 голосов
/ 20 января 2020

grpc не удается подключиться, даже когда я установил для своей функции jest test() asyn c ограничение 100000 мсек до истечения времени ожидания.

// terminal, after running jest --watch
● creates new record

    14 UNAVAILABLE: failed to connect to all addresses

      at Object.<anonymous>.exports.createStatusError (node_modules/grpc/src/common.js:91:15)
      at Object.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:1209:28)
      at InterceptingListener.Object.<anonymous>.InterceptingListener._callNext (node_modules/grpc/src/client_interceptors.js:568:42)
      at InterceptingListener.Object.<anonymous>.InterceptingListener.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:618:8)
      at callback (node_modules/grpc/src/client_interceptors.js:847:24)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 skipped, 2 total
Snapshots:   0 total
Time:        106.03s, estimated 116s
Ran all test suites related to changed files.

Watch Usage: Press w to show more.
owner@G700:~/PhpstormProjects/shopify/bu
 FAIL  functions/src/classes/__tests__/FirestoreConnection.test.ts (108.991s)
  ✕ creates new record (100029ms)
  ○ skipped 

  ● creates new record

    : Timeout - Async callback was not invoked within the 100000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 100000ms timeout specified by jest.setTimeout.Error:

      51 | 
      52 | 
    > 53 | test("creates new record", async () => {
         | ^
      54 |   const addedDocument = await db
      55 |     .createNew(RecordTypes.globalRule, {
      56 |       storeId : "dummyStoreId"

      at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Object.<anonymous> (functions/src/classes/__tests__/FirestoreConnection.test.ts:53:1)

  ● creates new record

    14 UNAVAILABLE: failed to connect to all addresses

      at Object.<anonymous>.exports.createStatusError (node_modules/grpc/src/common.js:91:15)
      at Object.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:1209:28)
      at InterceptingListener.Object.<anonymous>.InterceptingListener._callNext (node_modules/grpc/src/client_interceptors.js:568:42)
      at InterceptingListener.Object.<anonymous>.InterceptingListener.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:618:8)
      at callback (node_modules/grpc/src/client_interceptors.js:847:24)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 skipped, 2 total
Snapshots:   0 total
Time:        111.16s
Ran all test suites related to changed files.


// FirebaseConnection.ts, inside the class

  protected async addDocument(collectionName: string, documentData: object): Promise<firestore.DocumentSnapshot|null> {
    try {
      const newlyAddedDocument = await this.database
        .collection(collectionName)
        .add(documentData);

      return await newlyAddedDocument.get();
    }
    catch (e) {
      console.log(e, `=====error=====`);
      return null;
    }
  }

  // --------------- Public Methods

  public async createNew(type: RecordTypes, documentData: object): Promise<firestore.DocumentSnapshot|null> {
    this.verifySchemaIsCorrect(type, documentData);
    const collectionName = this.getCollectionName(type);

    return await this.addDocument(collectionName, documentData);
  }

// FirebaseConnection.test.ts
import * as firebaseTesting from "@firebase/testing";
import {RecordTypes} from "../../../../shared";

import FirestoreConnection from "../FirestoreConnection";

/* * * * * * * * * * * * * * * * * * * * *
                  Setup
* * * * * * * * * * * * * * * * * * * * */

const createTestDatabase = (credentials): any => {
  return firebaseTesting
    .initializeTestApp({
      projectId: 'testProject',
      auth: credentials
    })
    .firestore();
};

const nullAllApps = firebaseTesting
  .apps().map(app => app.delete());

const db = new FirestoreConnection('testShopDomain', createTestDatabase(null));


/* * * * * * * * * * * * * * * * * * * * *
                  Tests
* * * * * * * * * * * * * * * * * * * * */

test("creates new record", async () => {
  const addedDocument = await db
    .createNew(RecordTypes.globalRule, {
      storeId : "dummyStoreId"
      , globalPercent : 40
    });

  expect(addedDocument).toEqual({
    storeId : "dummyStoreId"
    , globalPercent : 40
    , badProp : 0
  });
}, 100000);

Кто-нибудь может сказать, почему это происходит? Глядя на документацию, это библиотека более низкого уровня: https://grpc.github.io/grpc/node/

Обновление

После того, как было предложено, чтобы сервер / эмулятор не был найден gRP C, я бежал firebase serve --only functions,firestore. Терминал показал эмуляторы, работающие на разных портах для обоих сервисов. Перезапуск jest --watch теперь выдает немного другую ошибку:

 2 UNKNOWN:

      at Object.<anonymous>.exports.createStatusError (node_modules/grpc/src/common.js:91:15)
      at Object.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:1209:28)
      at InterceptingListener.Object.<anonymous>.InterceptingListener._callNext (node_modules/grpc/src/client_interceptors.js:568:42)
      at InterceptingListener.Object.<anonymous>.InterceptingListener.onReceiveStatus (node_modules/grpc/src/client_interceptors.js:618:8)
      at callback (node_modules/grpc/src/client_interceptors.js:847:24)

Ответы [ 2 ]

0 голосов
/ 23 января 2020

Функции Firebase скрывали основную ошибку. Это было решено в 2 этапа:

  1. , разрешив вход в административный SDK с помощью firestore.setLogFunction ()
  2. projectId testProject недопустим. Изменение идентификатора проекта на testproject со всеми строчными буквами устранило эту ошибку.
0 голосов
/ 21 января 2020

Эта ошибка gRP C означает, что ни один сервер не работает по адресу, к которому вы пытаетесь подключиться, или по какой-либо причине не удается установить соединение с этим сервером. Если вы пытаетесь подключиться к локальному эмулятору Firestore, вы должны убедиться, что он работает и что вы можете подключиться к нему вне теста.

...