Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

"Invocations on test machines are not supported" when machines invoke actors#5353

Unanswered
franleplant asked this question inQ&A
Discussion options

I have this machine that usesfromPromise to wrap a rest call and later invoke it in some state and when I do

createTestModel(machine) I get

Invocations on test machines are not supported

Couldn't find any answer anywhere.

Will this be ever supported?

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Model-based testing is based on synchronous state transitions. The core principle is(state, event) => nextState where each transition should be deterministic (immediate, predictable).

But when you invoke an actor, they are "alive" and asynchronous. Test path generation requires determinism, and when we're invoking live actors, it becomes non-deterministic.

Can you give me a better idea of what you're trying to do? I can see a potential feature in which we can "simulate" invoked actors such that they are deterministic and synchronous, such as a promise that always resolves/rejects with the same value.

You must be logged in to vote
1 reply
@franleplant
Comment options

My code looks something like this

// Production upload actor implementationexportconstcreateUploadFileActor=()=>fromPromise(async({ input}:{input:{file:File;userId:string}}):Promise<ProfileData>=>{// get file from the dom and send it through an api call});// the actual machinereturnsetup({types:{context:{}asFileUploadContext,events:{}asFileUploadEvent,},actors:{uploadFile:createUploadFileActor(), ...actors},}).createMachine({id:'fileUpload',initial:'idle',context:{},states:{idle:{on:{UPLOAD_FILE:{target:'uploading',actions:assign({file:({ event})=>event.file,error:null,}),},},},uploading:{invoke:{id:'uploadFile',src:'uploadFile',input:({ context}:{context:FileUploadContext})=>({file:context.file!,userId:context.userId,}),onDone:{target:'success'...},onError:{target:'error'...},},        ...,},

As you can see, per the recommended way of handling "side effects" we've use thefromPromise, and the test looks something like this

describe('Success Scenarios',()=>{constmockActor=fromPromise(async({input:_input}:{input:{file:File;userId:string}}):Promise<ProfileData>=>{awaitnewPromise(resolve=>setTimeout(resolve,100));returnmockSuccessProfileData;});constmachine=createFileUploadMachine(userId,mockOnProfileParsed).provide({actors:{uploadFile:mockActor,},});constmodel=createTestModel(machine);constpaths=model.getShortestPaths();paths.forEach((path)=>{it(path.description,async()=>{render(<MyComponent/>);awaitpath.test({states:{           ...},events:{          ...}});});});});

So the only thing impeding full MBT (model based testing) with xstate is the actor. I don't really care about the actual actor, in fact we are trying to mock it, so it seems like xstate could provide an easy way of mocking an actor with something that makes it "deterministic and synchronous" so that we can run full MBT on pretty much any machine.

Alternatively we could, instead of the actor, we could modelfileUpload function with different states in the machine, but that would mean a lot of extra work.

Also, is it not that actors are just instances of a machine? Is it not thatfromPromise just creates a predictable machine from basically a promise? So how is that not deterministic? If it's not because of "side effect" it's pretty clear that we could add some test helpers that would turn an actor into a deterministic machine that would allow full MBTs.

Also, happy to contribute to this

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@franleplant@davidkpiano

[8]ページ先頭

©2009-2025 Movatter.jp