Skip to content

Commit

Permalink
test(grpc): revert case base-app-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Nov 12, 2024
1 parent fc16cd3 commit da0032d
Showing 1 changed file with 1 addition and 55 deletions.
56 changes: 1 addition & 55 deletions packages/grpc/test/fixtures/base-app-stream/src/provider/math.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as assert from 'assert';
import { GrpcMethod, GrpcStreamTypeEnum, Inject, MSProviderType, Provide, Provider } from '@midwayjs/core';
import { Context } from '../../../../../src';
import { GrpcMethod, GrpcStreamTypeEnum, MSProviderType, Provide, Provider } from '@midwayjs/core';
import { math } from '../interface';
import { Metadata } from '@grpc/grpc-js';

Expand All @@ -10,45 +8,17 @@ import { Metadata } from '@grpc/grpc-js';
@Provider(MSProviderType.GRPC, { package: 'math' })
export class Math implements math.Math {

@Inject()
ctx: Context;

sumDataList = [];

@GrpcMethod()
async add(data: math.AddArgs): Promise<math.Num> {
assert(this.ctx, 'should get context');
const { metadata } = this.ctx;
assert(metadata, 'should get metadata');

const rpcDefinition = metadata.get('rpc.definition');
assert(rpcDefinition[0] === 'math.Math', `should get rpc.definition, but got "${rpcDefinition}"`);

const rpcMethod = metadata.get('rpc.method');
assert(rpcMethod[0] === 'Add', `should get rpc.method, but got "${rpcMethod[0]}"`);

const rpcMethodType = metadata.get('rpc.method.type');
assert(rpcMethodType[0] === 'unary', `should get rpc.method.type, but got "${rpcMethodType[0]}"`);

return {
num: data.num + 2,
}
}

@GrpcMethod({type: GrpcStreamTypeEnum.DUPLEX, onEnd: 'duplexEnd' })
async addMore(message: math.AddArgs) {
const { metadata } = this.ctx;
assert(metadata, 'should get metadata');

const rpcDefinition = metadata.get('rpc.definition');
assert(rpcDefinition[0] === 'math.Math', `should get rpc.definition, but got "${rpcDefinition}"`);

const rpcMethod = metadata.get('rpc.method');
assert(rpcMethod[0] === 'AddMore', `should get rpc.method, but got "${rpcMethod[0]}"`);

const rpcMethodType = metadata.get('rpc.method.type');
assert(rpcMethodType[0] === 'bidi', `should get rpc.method.type, but got "${rpcMethodType[0]}"`);

this.ctx.write({
id: message.id,
num: message.num + 10,
Expand All @@ -61,18 +31,6 @@ export class Math implements math.Math {

@GrpcMethod({type: GrpcStreamTypeEnum.WRITEABLE })
async sumMany(args: math.AddArgs) {
const { metadata } = this.ctx;
assert(metadata, 'should get metadata');

const rpcDefinition = metadata.get('rpc.definition');
assert(rpcDefinition[0] === 'math.Math', `should get rpc.definition, but got "${rpcDefinition}"`);

const rpcMethod = metadata.get('rpc.method');
assert(rpcMethod[0] === 'SumMany', `should get rpc.method, but got "${rpcMethod[0]}"`);

const rpcMethodType = metadata.get('rpc.method.type');
assert(rpcMethodType[0] === 'server', `should get rpc.method.type, but got "${rpcMethodType[0]}"`);

this.ctx.write({
num: 1 + args.num
});
Expand All @@ -92,18 +50,6 @@ export class Math implements math.Math {

@GrpcMethod({type: GrpcStreamTypeEnum.READABLE, onEnd: 'sumEnd' })
async addMany(data: math.Num) {
const { metadata } = this.ctx;
assert(metadata, 'should get metadata');

const rpcDefinition = metadata.get('rpc.definition');
assert(rpcDefinition[0] === 'math.Math', `should get rpc.definition, but got "${rpcDefinition}"`);

const rpcMethod = metadata.get('rpc.method');
assert(rpcMethod[0] === 'AddMany', `should get rpc.method, but got "${rpcMethod[0]}"`);

const rpcMethodType = metadata.get('rpc.method.type');
assert(rpcMethodType[0] === 'client', `should get rpc.method.type, but got "${rpcMethodType[0]}"`);

this.sumDataList.push(data);
}

Expand Down

0 comments on commit da0032d

Please sign in to comment.