未验证 提交 858c54ec 编写于 作者: O openharmony_ci 提交者: Gitee

!5805 ServiceAbilityTest 修改---master

Merge pull request !5805 from HuangXW/ServiceAbilityTest
...@@ -49,25 +49,29 @@ class StubTest extends rpc.RemoteObject { ...@@ -49,25 +49,29 @@ class StubTest extends rpc.RemoteObject {
} }
} }
function sleep(delay) {
let start = new Date().getTime();
while (true) {
if (new Date().getTime() - start > delay) {
break;
}
}
}
export default { export default {
onStart(want) { onStart(want) {
console.debug('ACTS_SerivceAbilityServer 0425 ====>onStart .ts 0851 =' console.debug('ACTS_SerivceAbilityServer 0425 ====>onStart .ts 0851 ='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onStart", (err) => { }); commonEvent.publish("ACTS_SerivceAbilityServer_onStart", (err) => { });
}, },
onStop() { onStop() {
console.debug('ACTS_SerivceAbilityServer ====<onStop'); console.debug('ACTS_SerivceAbilityServer ====<onStop');
commonEvent.publish("ACTS_SerivceAbilityServer_onStop", (err) => { }); commonEvent.publish("ACTS_SerivceAbilityServer_onStop", (err) => { });
particleAbility.terminateSelf().then((data) => {
console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data));
}).catch((error) => {
console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error));
});
}, },
onCommand(want, restart, startId) { onCommand(want, restart, startId) {
console.debug('ACTS_SerivceAbilityServer ====>onCommand=' console.debug('ACTS_SerivceAbilityServer ====>onCommand='
+ "JSON(want)=" + JSON.stringify(want) + "JSON(want)=" + JSON.stringify(want)
+ " ,restart=" + restart + " ,startId=" + startId); + " ,restart=" + restart + " ,startId=" + startId);
if (want.action == 'ServiceStartService_0900') { if (want.action == 'ServiceStartService_0900') {
particleAbility.startAbility( particleAbility.startAbility(
{ {
...@@ -79,11 +83,7 @@ export default { ...@@ -79,11 +83,7 @@ export default {
}, },
} }
); );
particleAbility.terminateSelf().then((data) => { sleep(600)
console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data));
}).catch((error) => {
console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error));
});
} else if (want.action == 'ServiceStartService_1000') { } else if (want.action == 'ServiceStartService_1000') {
particleAbility.startAbility( particleAbility.startAbility(
{ {
...@@ -94,27 +94,17 @@ export default { ...@@ -94,27 +94,17 @@ export default {
action: "ServiceStartService_1000", action: "ServiceStartService_1000",
}, },
}, (err, data) => { }, (err, data) => {
console.debug('ACTS_SerivceAbilityServer start Ability 1000 callback=====' console.debug('ACTS_SerivceAbilityServer start Ability 1000 callback====='
+ err + ', data= ' + data + " , JSON." + JSON.stringify(data)); + err + ', data= ' + data + " , JSON." + JSON.stringify(data));
particleAbility.terminateSelf().then((data) => { }
console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data));
}).catch((error) => {
console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error));
});
}
); );
} else { } else {
commonEvent.publish("ACTS_SerivceAbilityServer_onCommand" + "_" + want.action, (err) => { commonEvent.publish("ACTS_SerivceAbilityServer_onCommand" + "_" + want.action, (err) => {
if (!err.code) { if (!err.code) {
if (want.action == 'PageStartService_0100' || want.action == 'PageStartService_0200' if (want.action == 'PageStartService_0100' || want.action == 'PageStartService_0200'
|| want.action == 'PageStartService_0301' || want.action == 'PageStartService_0401') { || want.action == 'PageStartService_0301' || want.action == 'PageStartService_0401') {
console.debug('ACTS_SerivceAbilityServer_onCommand 100 200 301 401.terminateSelf()=====>' console.debug('ACTS_SerivceAbilityServer_onCommand 100 200 301 401.=====>'
+ want.action); + want.action);
particleAbility.terminateSelf().then((data) => {
console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data));
}).catch((error) => {
console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error));
});
} }
} else { } else {
console.debug('ACTS_SerivceAbilityServer_onCommand publish err=====>' + err); console.debug('ACTS_SerivceAbilityServer_onCommand publish err=====>' + err);
...@@ -126,25 +116,26 @@ export default { ...@@ -126,25 +116,26 @@ export default {
console.info('ACTS_SerivceAbilityServer ====< onConnect'); console.info('ACTS_SerivceAbilityServer ====< onConnect');
try { try {
console.debug('ACTS_SerivceAbilityServer ====>onConnect=' console.debug('ACTS_SerivceAbilityServer ====>onConnect='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onConnect" + "_" + want.action, (err) => { });
function onConnectCallback(element, remote) { function onConnectCallback(element, remote) {
console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> mConnIdJs=' console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> mConnIdJs='
+ JSON.stringify(mConnIdJs) + " , " + mConnIdJs); + JSON.stringify(mConnIdJs) + " , " + mConnIdJs);
console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> element=' console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> element='
+ JSON.stringify(element) + " , " + element); + JSON.stringify(element) + " , " + element);
console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> remote=' console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> remote='
+ JSON.stringify(remote) + " , " + remote); + JSON.stringify(remote) + " , " + remote);
} }
function onDisconnectCallback(element) { function onDisconnectCallback(element) {
console.debug('ACTS_SerivceAbilityServer_onDisconnectCallback ====> element=' console.debug('ACTS_SerivceAbilityServer_onDisconnectCallback ====> element='
+ JSON.stringify(element) + " , " + element); + JSON.stringify(element) + " , " + element);
} }
function onFailedCallback(code) { function onFailedCallback(code) {
console.debug('ACTS_SerivceAbilityServer_onFailedCallback ====> code=' console.debug('ACTS_SerivceAbilityServer_onFailedCallback ====> code='
+ JSON.stringify(code) + " , " + code) + JSON.stringify(code) + " , " + code)
} }
if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400' if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400'
|| want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1600') { || want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1600') {
mConnIdJs = particleAbility.connectAbility( mConnIdJs = particleAbility.connectAbility(
{ {
bundleName: serversecond_bundleName, bundleName: serversecond_bundleName,
...@@ -157,8 +148,6 @@ export default { ...@@ -157,8 +148,6 @@ export default {
onFailed: onFailedCallback, onFailed: onFailedCallback,
}, },
) )
} else {
commonEvent.publish("ACTS_SerivceAbilityServer_onConnect" + "_" + want.action, (err) => { });
} }
} catch (err) { } catch (err) {
console.log("ACTS_SerivceAbilityServer ====< error:" + err) console.log("ACTS_SerivceAbilityServer ====< error:" + err)
...@@ -168,44 +157,34 @@ export default { ...@@ -168,44 +157,34 @@ export default {
}, },
onDisconnect(want) { onDisconnect(want) {
console.debug('ACTS_SerivceAbilityServer ====>onDisConnect=' console.debug('ACTS_SerivceAbilityServer ====>onDisConnect='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onDisConnect", (err) => { commonEvent.publish("ACTS_SerivceAbilityServer_onDisConnect_" + want.action, (err) => {
if (err.code) { console.debug('ACTS_SerivceAbilityServer_onDisConnect ===' + want.action);
console.debug('ACTS_SerivceAbilityServer_onDisConnect publish err=====>' + err);
} else {
console.debug('ACTS_SerivceAbilityServer_onDisConnect featureAbility.terminateSelf()=====<'
+ want.action);
if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400'
|| want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501'
|| want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601'
) {
particleAbility.disconnectAbility(mConnIdJs, (err) => {
console.debug("=ACTS_SerivceAbilityServer_onDisConnect 13 14 15 16 err====>"
+ ("json err=") + JSON.stringify(err) + " , " + want.action);
})
}
particleAbility.terminateSelf().then((data) => {
console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data));
}).catch((error) => {
console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error));
});
}
}); });
if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400'
|| want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501'
|| want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601'
) {
particleAbility.disconnectAbility(mConnIdJs, (err) => {
console.debug("=ACTS_SerivceAbilityServer_onDisConnect 13 14 15 16 err====>"
+ ("json err=") + JSON.stringify(err) + " , " + want.action);
})
}
}, },
onReady() { onReady() {
console.debug('ACTS_SerivceAbilityServer ====<onReady'); console.debug('ACTS_SerivceAbilityServer ====<onReady');
}, },
onReconnect(want) { onReconnect(want) {
console.debug('ACTS_SerivceAbilityServer ====>onReconnect=' console.debug('ACTS_SerivceAbilityServer ====>onReconnect='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onReconnect" + "_" + want.action, (err) => { }); commonEvent.publish("ACTS_SerivceAbilityServer_onReconnect" + "_" + want.action, (err) => { });
}, },
OnAbilityConnectDone(element, remoteObject, resultCode) { OnAbilityConnectDone(element, remoteObject, resultCode) {
console.debug('ACTS_SerivceAbilityServer ====>OnAbilityConnectDone=' console.debug('ACTS_SerivceAbilityServer ====>OnAbilityConnectDone='
+ element + " , JSON." + JSON.stringify(element) + element + " , JSON." + JSON.stringify(element)
+ remoteObject + " , JSON." + JSON.stringify(remoteObject) + remoteObject + " , JSON." + JSON.stringify(remoteObject)
+ resultCode + " , JSON." + JSON.stringify(resultCode) + resultCode + " , JSON." + JSON.stringify(resultCode)
); );
commonEvent.publish("ACTS_SerivceAbilityServer_OnAbilityConnectDone", (err) => { }); commonEvent.publish("ACTS_SerivceAbilityServer_OnAbilityConnectDone", (err) => { });
}, },
}; };
\ No newline at end of file
...@@ -49,44 +49,41 @@ class StubTest extends rpc.RemoteObject { ...@@ -49,44 +49,41 @@ class StubTest extends rpc.RemoteObject {
} }
} }
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default { export default {
onStart(want) { onStart(want) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onStart=' console.debug('ACTS_SerivceAbilityServerSecond ====>onStart='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onStart", (err) => { }); commonEvent.publish("ACTS_SerivceAbilityServerSecond_onStart", (err) => { });
}, },
onStop() { onStop() {
console.debug('ACTS_SerivceAbilityServerSecond ====<onStop'); console.debug('ACTS_SerivceAbilityServerSecond ====<onStop');
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onStop", (err) => { }); commonEvent.publish("ACTS_SerivceAbilityServerSecond_onStop", (err) => { });
particleAbility.terminateSelf().then((data) => {
console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data));
}).catch((error) => {
console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error));
});
}, },
onCommand(want, restart, startId) { onCommand(want, restart, startId) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onCommand=' console.debug('ACTS_SerivceAbilityServerSecond ====>onCommand='
+ "JSON(want)=" + JSON.stringify(want) + "JSON(want)=" + JSON.stringify(want)
+ " ,restart=" + restart + " ,startId=" + startId); + " ,restart=" + restart + " ,startId=" + startId);
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onCommand" + "_" + want.action, (err) => { }); commonEvent.publish("ACTS_SerivceAbilityServerSecond_onCommand" + "_" + want.action, (err) => {
particleAbility.terminateSelf().then((data) => { console.debug("ACTS_SerivceAbilityServerSecond_onCommand" + "_" + want.action +
console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data)); "err: " + JSON.stringify(err))
}).catch((error) => { });
console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error)); sleep(500)
});
}, },
onConnect(want) { onConnect(want) {
console.info('ACTS_SerivceAbilityServerSecond ====< onConnect'); console.info('ACTS_SerivceAbilityServerSecond ====< onConnect');
try { try {
console.debug('ACTS_SerivceAbilityServerSecond ====>onConnect=' console.debug('ACTS_SerivceAbilityServerSecond ====>onConnect='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
function onConnectCallback(element, remote) { function onConnectCallback(element, remote) {
console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> want.action=' console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> want.action='
+ JSON.stringify(want.action) + " , " + want.action); + JSON.stringify(want.action) + " , " + want.action);
console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> element=' console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> element='
+ JSON.stringify(element) + " , " + element); + JSON.stringify(element) + " , " + element);
console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> remote=' console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> remote='
+ JSON.stringify(remote) + " , " + remote); + JSON.stringify(remote) + " , " + remote);
if (want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1600') { if (want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1600') {
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action, (err) => { commonEvent.publish("ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action, (err) => {
console.debug("publish = ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action); console.debug("publish = ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action);
...@@ -96,12 +93,12 @@ export default { ...@@ -96,12 +93,12 @@ export default {
function onDisconnectCallback(element) { function onDisconnectCallback(element) {
console.debug('ACTS_SerivceAbilityServerSecond_onDisconnectCallback ====> element=' console.debug('ACTS_SerivceAbilityServerSecond_onDisconnectCallback ====> element='
+ JSON.stringify(element) + " , " + element); + JSON.stringify(element) + " , " + element);
} }
function onFailedCallback(code) { function onFailedCallback(code) {
console.debug('ACTS_SerivceAbilityServerSecond_onFailedCallback ====> code=' console.debug('ACTS_SerivceAbilityServerSecond_onFailedCallback ====> code='
+ JSON.stringify(code) + " , " + code) + JSON.stringify(code) + " , " + code)
} }
if (want.action == 'ServiceConnectService_1500') { if (want.action == 'ServiceConnectService_1500') {
mConnIdJs = particleAbility.connectAbility( mConnIdJs = particleAbility.connectAbility(
...@@ -153,26 +150,21 @@ export default { ...@@ -153,26 +150,21 @@ export default {
}, },
onDisconnect(want) { onDisconnect(want) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onDisConnect=' console.debug('ACTS_SerivceAbilityServerSecond ====>onDisConnect='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onDisConnect", (err) => { commonEvent.publish("ACTS_SerivceAbilityServerSecond_onDisConnect_" + want.action, (err) => {
if (err.code) { if (err.code) {
console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect publish err=====>' + err); console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect publish err=====>' + err);
} else { } else {
console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect featureAbility.terminateSelf()=====<' console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect =====<'
+ want.action); + want.action);
if (want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501' if (want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501'
|| want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601' || want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601'
|| want.action == 'ServiceConnectService_1590') { || want.action == 'ServiceConnectService_1590') {
particleAbility.disconnectAbility(mConnIdJs, (err) => { particleAbility.disconnectAbility(mConnIdJs, (err) => {
console.debug("=ACTS_SerivceAbilityServerSecond_onDisConnect err====>" console.debug("=ACTS_SerivceAbilityServerSecond_onDisConnect err====>"
+ ("json err=") + JSON.stringify(err) + " , " + want.action); + ("json err=") + JSON.stringify(err) + " , " + want.action);
}) })
} }
particleAbility.terminateSelf().then((data) => {
console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data));
}).catch((error) => {
console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error));
});
} }
}); });
}, },
...@@ -181,13 +173,13 @@ export default { ...@@ -181,13 +173,13 @@ export default {
}, },
onReconnect(want) { onReconnect(want) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onReconnect=' console.debug('ACTS_SerivceAbilityServerSecond ====>onReconnect='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
}, },
OnAbilityConnectDone(element, remoteObject, resultCode) { OnAbilityConnectDone(element, remoteObject, resultCode) {
console.debug('ACTS_SerivceAbilityServerSecond ====>OnAbilityConnectDone=' console.debug('ACTS_SerivceAbilityServerSecond ====>OnAbilityConnectDone='
+ element + " , JSON." + JSON.stringify(element) + element + " , JSON." + JSON.stringify(element)
+ remoteObject + " , JSON." + JSON.stringify(remoteObject) + remoteObject + " , JSON." + JSON.stringify(remoteObject)
+ resultCode + " , JSON." + JSON.stringify(resultCode) + resultCode + " , JSON." + JSON.stringify(resultCode)
); );
commonEvent.publish("ACTS_SerivceAbilityServerSecond_OnAbilityConnectDone", (err) => { }); commonEvent.publish("ACTS_SerivceAbilityServerSecond_OnAbilityConnectDone", (err) => { });
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册