Skip to content

Commit

Permalink
Fix e2e test code (#61)
Browse files Browse the repository at this point in the history
* 🐛 fix

Signed-off-by: vankichi <[email protected]>

* 🐛 fix

Signed-off-by: vankichi <[email protected]>

* 🐛 fix

Signed-off-by: vankichi <[email protected]>

* 🐛 fix

Signed-off-by: vankichi <[email protected]>

* 🐛 fix

Signed-off-by: vankichi <[email protected]>

* fix: vald docker image tag

Signed-off-by: hlts2 <[email protected]>

* feat: generate code from proto and update e2e test code

Signed-off-by: hlts2 <[email protected]>

* 🐛 fix example

Signed-off-by: vankichi <[email protected]>

* 🐛 fix example

Signed-off-by: vankichi <[email protected]>

* Enabled E2E test for Typescript (#63)

* feat: add ts e2e test

Signed-off-by: hlts2 <[email protected]>

* fix: fails test for assertion

Signed-off-by: hlts2 <[email protected]>

* feat: add step to verify example ts

Signed-off-by: hlts2 <[email protected]>

* feat: add tsconfig

Signed-off-by: hlts2 <[email protected]>

* fix: debug log message

Signed-off-by: hlts2 <[email protected]>

* fix: delete any keyword

Signed-off-by: hlts2 <[email protected]>

* fix: delete any keyword

Signed-off-by: hlts2 <[email protected]>

* fix: use process exit when an error occurs

Signed-off-by: hlts2 <[email protected]>

* fix: package updatge

Signed-off-by: hlts2 <[email protected]>

* fix: add new package for build error

Signed-off-by: hlts2 <[email protected]>

---------

Signed-off-by: hlts2 <[email protected]>

---------

Signed-off-by: vankichi <[email protected]>
Signed-off-by: hlts2 <[email protected]>
Co-authored-by: hlts2 <[email protected]>
  • Loading branch information
vankichi and hlts2 authored Dec 25, 2023
1 parent 902e3a9 commit 1e1cd86
Show file tree
Hide file tree
Showing 93 changed files with 20,347 additions and 50,579 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
helm repo add vald https://vald.vdaas.org/charts
helm install \
--values ${VALUES} \
--set defaults.image.tag=latest \
--set defaults.image.tag=nightly \
--set agent.ngt.dimension=300 \
--set agent.ngt.auto_index_length=2 \
--set agent.minReplicas=1 \
Expand Down Expand Up @@ -61,6 +61,19 @@ jobs:
run: |
npm install
npm pack
- name: verify example codes (ts)
run: |
kubectl port-forward statefulset/vald-agent-ngt 8081:8081 &
pid=$!
version=`make vald/client/node/version/print`
npm install -g ts-node
cd example-ts
npm install ../vald-client-node-${version}.tgz -s -f
DIM=300 ts-node example.ts
kill $pid
- name: verify example codes (js)
run: |
version=`make vald/client/node/version/print`
Expand All @@ -71,19 +84,6 @@ jobs:
DIM=300 node example.js
kill $pid
# - name: verify example codes (ts)
# run: |
# kubectl port-forward statefulset/vald-agent-ngt 8081:8081 &
# pid=$!
#
# version=`make vald/client/node/version/print`
# npm install -g ts-node
#
# cd example-ts
# npm install ../vald-client-node-${version}.tgz -s -f
# DIM=300 ts-node example.ts
#
# kill $pid
publish:
if: startsWith( github.ref, 'refs/tags/')
needs:
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ $(NODE_ROOT)/$(SHADOW_ROOT)/%/index.js: $(NODE_ROOT)/$(SHADOW_ROOT)/%
sed -e "s:$</::" | \
sed -e "s:_grpc_pb.js::"`; \
echo "module.exports.$${name} = require(\"./$${name}_pb\");" >> $@; \
echo "module.exports.$${name}_grpc = require(\"./$${name}_grpc_pb\");" >> $@; \
if [ ! "$${name}" = "payload" ]; then \
echo "module.exports.$${name}_grpc = require(\"./$${name}_pb.grpc-client\");" >> $@; \
fi; \
done
$(NODE_ROOT)/$(SHADOW_ROOT)/%/index.d.ts: $(NODE_ROOT)/$(SHADOW_ROOT)/%
rm -rf $@
Expand Down
19 changes: 11 additions & 8 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ version: v1
managed:
enabled: true
plugins:
- plugin: buf.build/protocolbuffers/js
out: src/
opt: import_style=commonjs
- plugin: buf.build/grpc/node
out: src
opt: grpc_js,import_style=commonjs
- plugin: buf.build/community/timostamm-protobuf-ts
out: src/
out: src
# https://github.com/timostamm/protobuf-ts/blob/main/MANUAL.md#the-protoc-plugin
opt: add_pb_suffix,client_grpc1,generate_dependencies,keep_enum_prefix,ts_nocheck,use_proto_field_name
opt:
- add_pb_suffix
- client_grpc1
- generate_dependencies
- keep_enum_prefix
- ts_nocheck
- use_proto_field_name
- output_javascript
- output_legacy_commonjs
- eslint_disable
32 changes: 17 additions & 15 deletions example-ts/example.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as grpc from "@grpc/grpc-js";
import { v1_vald, v1_payload } from "vald-client-node";
import type { Insert_Request, Search_Request, Remove_Request } from "vald-client-node/src/vald/v1/payload/payload_pb";

const addr = "localhost:8081";
const DIM = process.env.DIM || 4;
Expand Down Expand Up @@ -38,7 +39,7 @@ const main = async () => {
grpc.credentials.createInsecure()
);

const insertFunc = (req: any) => {
const insertFunc = async (req: Insert_Request) => {
return new Promise((resolve, reject) => {
iclient.insert(req, (err, resp) => {
if (err) {
Expand All @@ -49,13 +50,13 @@ const main = async () => {
});
});
};
insertFunc(ireq)
.then(async (res) => {
console.log("resp: ", res);
await insertFunc(ireq)
.then((res) => {
console.log("insert resp: ", res);
})
.catch((e) => {
console.log("err: ", e);
return -1;
process.exit(1);
});

const second = 100;
Expand All @@ -79,7 +80,7 @@ const main = async () => {
grpc.credentials.createInsecure()
);

const searchFunc = (req: any) => {
const searchFunc = async (req: Search_Request) => {
return new Promise((resolve, reject) => {
sclient.search(req, (err, resp) => {
if (err) {
Expand All @@ -90,13 +91,13 @@ const main = async () => {
});
});
};
searchFunc(sreq)
.then((res: any) => {
console.log("res: ", res, "\n");
await searchFunc(sreq)
.then((res) => {
console.log("search res: ", res, "\n");
})
.catch((e) => {
console.log("err: ", e);
return -1;
process.exit(1);
});

// remove
Expand All @@ -117,7 +118,7 @@ const main = async () => {
grpc.credentials.createInsecure()
);

const removeFunc = (req: any) => {
const removeFunc = async (req: Remove_Request) => {
return new Promise((resolve, reject) => {
rclient.remove(req, (err, resp) => {
if (err) {
Expand All @@ -128,14 +129,15 @@ const main = async () => {
});
});
};
removeFunc(rreq)
.then((res: any) => {
console.log("res: ", res, "\n");
await removeFunc(rreq)
.then((res) => {
console.log("remove res: ", res, "\n");
})
.catch((e) => {
console.log("err: ", e);
return -1;
process.exit(1);
});
process.exit(0);
};

main();
11 changes: 11 additions & 0 deletions example-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
}
}
94 changes: 50 additions & 44 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,26 @@ const main = async () => {
}

// insert
const ivec = new payload.Object.Vector();
ivec.setId(ID);
ivec.setVectorList(vec);
const ivec = payload.Object_Vector.create({
id: ID,
vector: vec,
});

const icfg = new payload.Insert.Config();
icfg.setSkipStrictExistCheck(false);
const icfg = payload.Insert_Config.create({
skip_strict_exist_check: false,
});

const ireq = new payload.Insert.Request();
ireq.setVector(ivec);
ireq.setConfig(icfg);
const ireq = payload.Insert_Request.create({
vector: ivec,
config: icfg,
});

const iclient = new insert.InsertClient(
addr,
grpc.credentials.createInsecure()
grpc.credentials.createInsecure(),
);

const insertFunc = (req) => {
const insertFunc = async (req) => {
return new Promise((resolve, reject) => {
iclient.insert(req, (err, resp) => {
if (err) {
Expand All @@ -52,37 +55,38 @@ const main = async () => {
});
};
console.log("Insert start");
insertFunc(ireq)
await insertFunc(ireq)
.then((res) => {
console.log("res: ", res);
console.log("insert res: ", res);
})
.catch((e) => {
console.log("err: ", e);
return -1;
console.log("insert err: ", e);
process.exit(1);
});

// Wait for createIndex completed
const second = 120;
const second = 90;
await sleep(second);

// search
const scfg = new payload.Search.Config();
scfg.setNum(10);
scfg.setMinNum(1);
scfg.setRadius(-1.0);
scfg.setEpsilon(0.01);
scfg.setTimeout(3000000000);
const scfg = payload.Search_Config.create({
num: 10,
min_num: 1,
radius: -1,
epsilon: 0.01,
timeout: 3000000000,
});

const sreq = new payload.Search.Request();
sreq.setVectorList(vec);
sreq.setConfig(scfg);
const sreq = payload.Search_Request.create({
vector: vec,
config: scfg,
});

const sclient = new search.SearchClient(
addr,
grpc.credentials.createInsecure()
grpc.credentials.createInsecure(),
);

const searchFunc = (req) => {
const searchFunc = async (req) => {
return new Promise((resolve, reject) => {
sclient.search(req, (err, resp) => {
if (err) {
Expand All @@ -94,28 +98,30 @@ const main = async () => {
});
};
console.log("Search start");
searchFunc(sreq)
await searchFunc(sreq)
.then((res) => {
console.log("res: ", res, "\n");
console.log("search res: ", res);
})
.catch((e) => {
console.log("err: ", e);
return -1;
process.exit(1);
});

const rcfg = new payload.Remove.Config();
rcfg.setSkipStrictExistCheck(false);
const robjId = new payload.Object.ID();
robjId.setId(ID);
const rreq = new payload.Remove.Request();
rreq.setId(robjId);
rreq.setConfig(rcfg);

const rcfg = payload.Remove_Config.create({
skip_strict_exist_check: false,
});
const robjId = payload.Object_ID.create({
id: ID,
});
const rreq = payload.Remove_Request.create({
id: robjId,
config: rcfg,
});
const rclient = new remove.RemoveClient(
addr,
grpc.credentials.createInsecure()
grpc.credentials.createInsecure(),
);
const removeFunc = (req) => {
const removeFunc = async (req) => {
return new Promise((resolve, reject) => {
rclient.remove(req, (err, resp) => {
if (err) {
Expand All @@ -126,15 +132,15 @@ const main = async () => {
});
});
};
console.log("Remove start");
removeFunc(rreq)
await removeFunc(rreq)
.then((res) => {
console.log("res: ", res, "\n");
console.log("remove res: ", res);
})
.catch((e) => {
console.log("err: ", e);
return -1;
process.exit(1);
});
process.exit(0);
};

main();
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import v1_agent_core = require("./src/vald/v1/agent/core");
import v1_payload = require("./src/vald/v1/payload");
import v1_vald = require("./src/vald/v1/vald");
import v1_payload = require("./src/vald/v1/payload");
declare const _default: {
v1_agent_core: typeof v1_agent_core,
v1_payload: typeof v1_payload,
v1_vald: typeof v1_vald,
v1_payload: typeof v1_payload,
};
export = _default;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports.v1_agent_core = require("./src/vald/v1/agent/core");
module.exports.v1_payload = require("./src/vald/v1/payload");
module.exports.v1_vald = require("./src/vald/v1/vald");
module.exports.v1_payload = require("./src/vald/v1/payload");
Loading

0 comments on commit 1e1cd86

Please sign in to comment.