shared store resource pool #10010#10029
shared store resource pool #10010#10029christian-bromann merged 8 commits intowebdriverio:mainfrom pedrorfernandes:main
Conversation
|
@christian-bromann I will create docs + tests for this once the API is approved I had to modify the To not break contract with |
christian-bromann
left a comment
There was a problem hiding this comment.
Some comments. After we agree on the implementation, let's make sure to add some unit tests and docs.
christian-bromann
left a comment
There was a problem hiding this comment.
One comment but the implementation looks good to me. Let's add some tests for it.
| import { getValue, setValue, setPort } from './client.js' | ||
| import { getValue, setValue, setPort, setResourcePool, getValueFromPool, addValueToPool } from './client.js' | ||
| import type { SharedStoreServiceCapabilities } from './types.js' | ||
| import type { JsonArray } from '@wdio/types' |
There was a problem hiding this comment.
We already import types in line 1, let's merge these.
There was a problem hiding this comment.
oops, added now
will work on tests tomorrow
| resourcePoolStore.set(key, value) | ||
| return res.end() | ||
| }) | ||
| .post('/getValueFromPool/:key', async (req, res, next) => { |
There was a problem hiding this comment.
@christian-bromann setting this to .get caused me issues, unit tests that throw errors would hang for 2s instead of an immediate reply. .post() throws the error immediately
There was a problem hiding this comment.
Let's fix the unit test then, this should definitely be a get method. Given it is not really a user facing API I am happy to ignore the url path.
There was a problem hiding this comment.
figured it out, got has a retry mechanism on error, I've set all throwHttpErrors: false, retry: { limit: 0 }
There was a problem hiding this comment.
also, to note: GET operations should not modify the state of data, that's why got was retrying, assuming that it wouldn't make a difference in the server. A POST operation is more suited to our api call because it's actually modifying internal data
| const key = req.params.key as string | ||
|
|
||
| if (!resourcePoolStore.has(key)) { | ||
| next(new Error(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`)) |
There was a problem hiding this comment.
@christian-bromann I had to change throwing to next(new Error, this is the correct way for polka to throw error messages
There was a problem hiding this comment.
sounds good, let's do:
| next(new Error(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`)) | |
| return next(new Error(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`)) |
There was a problem hiding this comment.
changed to
return next(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`)`because new Error serializes to {}, serializing all errors by hand is too cumbersome
Polka recommends to just next(string) because this throws the error
I've added a catch + throw error on the client to read this message
| }) | ||
|
|
||
| describe('and the timeout is not specified', () => { | ||
| it('should return a value within the default timeout', async () => { |
There was a problem hiding this comment.
@christian-bromann I couldn't test the max timeout situation
the issue is: got.post needs a free event loop to run it's flush() and dispatch the request
I would need to release the event loop so that got can work. It doesn't expose the flush fn for us to make it work immediately
However, using vi.useFakeTimers() cancels all timers. This means that in the test i can not release the event loop with a setTimeout and take it back later. got can not run this way
I couldn't figure out a way to jump start got without releasing the event loop
There was a problem hiding this comment.
also the test for timeout takes
✓ packages/wdio-shared-store-service/tests/server.test.ts (14) 1281ms
doesn't affect the unit test pipeline a lot, but want to know your thoughts
christian-bromann
left a comment
There was a problem hiding this comment.
Some comments, great work so far 👍
| resourcePoolStore.set(key, value) | ||
| return res.end() | ||
| }) | ||
| .post('/getValueFromPool/:key', async (req, res, next) => { |
There was a problem hiding this comment.
Let's fix the unit test then, this should definitely be a get method. Given it is not really a user facing API I am happy to ignore the url path.
| const key = req.params.key as string | ||
|
|
||
| if (!resourcePoolStore.has(key)) { | ||
| next(new Error(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`)) |
There was a problem hiding this comment.
sounds good, let's do:
| next(new Error(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`)) | |
| return next(new Error(`'${key}' resource pool does not exist. Set it first using 'setResourcePool'`)) |
| const errHandler = (err: Response<Error>) => { | ||
| log.warn(err.statusCode, err.statusMessage, err.url, err.body) | ||
| const errHandler = (err: RequestError) => { | ||
| throw new Error(`${err.response?.body || 'Shared store server threw an error'}`) |
There was a problem hiding this comment.
@christian-bromann please validate this
before: the polka server would crash on throw error inside the HTTP handler, and all wdio processes crashed suddenly
now: the polka server returns an error, this client throws it to wdio, the message is logged, the worker crashes, but wdio process continues on to the next test
i think this was the desired behaviour, not to immediately crash all running suites
christian-bromann
left a comment
There was a problem hiding this comment.
Thank you for all this work. I want to include this into the next release so I will go ahead, merge this and address the missing pieces separately.
| const errHandler = (err: Response<Error>) => { | ||
| log.warn(err.statusCode, err.statusMessage, err.url, err.body) | ||
| const errHandler = (err: RequestError) => { | ||
| throw new Error(`${err.response?.body || 'Shared store server threw an error'}`) |
Solves #10010
Proposed changes
Types of changes
Checklist
Further comments
Reviewers: @webdriverio/project-committers